Shiny doesn't expect to click bar to render chart

Hi guys

I am using the shinydashboard package to create a graphics app. It has date period as default parameters. When I run the app it already displays the first graphic. How can I prevent shiny from doing this and wait for me to click the menu first?

Att.

...

Hi,

Welcome to the RStudio community!

The easiest way of executing code only under certain conditions is by wrapping it in an observeEvent statement like this:

library(shiny)

ui <- fluidPage(
  actionButton("myButton", "Click me"),
  plotOutput("myPlot")
)

server <- function(input, output, session){
  
  data(iris)
  
  observeEvent(input$myButton, {
    
    output$myPlot = renderPlot({
      plot(iris)
    })
    
  })

}

shinyApp(ui = ui, server = server)

The plot will only be created once the button is clicked and the observeEvent activated.
More details on the function can be read here: https://shiny.rstudio.com/reference/shiny/1.0.3/observeEvent.html

By the way, in future I encourage you to create a reprex when you have a question where you provide us with minimal code and data to recreate the issue so it's easier for all to understand and help you out. You can find details on creating one here:

Hope this helps,
PJ

Shiny
Thanks. I'll try. Use this way. The problem is that the sidebar responds to the click. I should not run the graph until I click on the bar.
Att.

Hi,

If you can't fix it with the information I provided, please create a reprex as suggested above and we can take another look at it.

PJ