-
Notifications
You must be signed in to change notification settings - Fork 23
/
1-madlibs.R
36 lines (32 loc) · 885 Bytes
/
1-madlibs.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
library(shiny)
generate_story <- function(noun, verb, adjective, adverb) {
glue::glue("
Once upon a time, there was a {adjective} {noun} who loved to
{verb} {adverb}. It was the funniest thing ever!
")
}
ui <- fluidPage(
titlePanel("Mad Libs Game"),
sidebarLayout(
sidebarPanel(
textInput("noun1", "Enter a noun:", ""),
textInput("verb", "Enter a verb:", ""),
textInput("adjective", "Enter an adjective:", ""),
textInput("adverb", "Enter an adverb:", ""),
actionButton("submit", "Create Story")
),
mainPanel(
h3("Your Mad Libs Story:"),
textOutput("story")
)
)
)
server <- function(input, output) {
story <- eventReactive(input$submit, {
generate_story(input$noun1, input$verb, input$adjective, input$adverb)
})
output$story <- renderText({
story()
})
}
shinyApp(ui = ui, server = server)