R Shiny eventReactive actionBotton interaction -
i have actionbotton
randomly pick 1 column first 5 columns dataset mtcars
, plot it.
now actionbotton
job chart not plotted @ first place when app launched.
is there way have plotted when shiny app launched.
library(shiny) server <- function(input, output) { x = eventreactive(input$plot,{ mtcars }) output$plot = renderplot({ = sample(1:5,1) plot(x()[,i],ylab=names(mtcars)[i]) }) } ui <- fluidpage( actionbutton("plot","randomly plot"), plotoutput("plot") ) shinyapp(ui = ui, server = server)
you can add condition button hasn't been clicked. note button works counter if hasn't been clicked value 0.
library(shiny) server <- function(input, output) { x = eventreactive(input$plot,{ mtcars }) output$plot = renderplot({ = sample(1:5,1) if(input$plot == 0){ return(plot(mtcars[,i],ylab=names(mtcars)[i])) } plot(x()[,i],ylab=names(mtcars)[i]) }) } ui <- fluidpage( actionbutton("plot","randomly plot"), plotoutput("plot") ) shinyapp(ui = ui, server = server)
Comments
Post a Comment