2

Below I made a small example of an app that allows the user to select two variables from the diamonds dataset. The selected variables are returned by a textOutput() after activating an actionButton().

I can select default inputs for the two selectizeInput() field, which I did. However, these default inputs are not return in the textOutput() field, because that is waiting for the actionButton() to be activated.

My question is: how can I run the reactive expression text1Reactive <- eventReactive() once on startup, and then have it update every time the actionButton() is clicked?

ui <- fluidPage(
  selectizeInput("xVar","Select X-variable",colnames(diamonds),selected='carat'),
  selectizeInput("yVar","Select Y-variable",colnames(diamonds),selected='cut'),
  actionButton("go","Update variables"),
  textOutput("text1")
)

server <- function(input, output) {
  text1Reactive <- eventReactive(input$go,{
    paste("X =",input$xVar,". Y =",input$yVar)
  })

  output$text1 <- renderText({
    text1Reactive()
  })
}

shinyApp(ui = ui, server = server)
P1storius
  • 917
  • 5
  • 12

0 Answers0