I have an actionBotton to randomly pick one column from the first 5 columns from the dataset mtcars and plot it.
Now the actionBotton could do its job but the chart is not plotted at the first place when the app is launched.
Is there any way to have it plotted when the Shiny app is launched.
library(shiny)
server <- function(input, output) {
X = eventReactive(input$plot,{
mtcars
})
output$plot = renderPlot({
i = sample(1:5,1)
plot(X()[,i],ylab=names(mtcars)[i])
})
}
ui <- fluidPage(
actionButton("plot","randomly plot"),
plotOutput("plot")
)
shinyApp(ui = ui, server = server)
