daattali / shinycssloaders

⌛ Add loading animations to a Shiny output while it's recalculating
https://daattali.com/shiny/shinycssloaders-demo/
Other
399 stars 45 forks source link

withspinner keeps on working with observeEvent #36

Closed nrajsab closed 4 years ago

nrajsab commented 4 years ago

I understand this issue has already been resolved but i think my case is different . I have a shiny alert which checks for certain condition and if condition matches then whole report runs else report won't run. So I added observeEvent for shiny alert , but now the spinner runs even before action button is clicked. Any help is greatly appreciated , thanks again in advance.

ui <- fluidRow(box(title = "Sales Pre vs Post", status = "primary", height = "500", width = 12, solidHeader = TRUE, withSpinner(plotOutput("plot1"), type = 2)))

server <- observeEvent(input$go,{ if(as.numeric(Sys.Date() - as.Date(input$date1)) >= as.numeric(input$radio) ) { op_sql <- eventReactive(input$go,{ script }) output$plot1 <- plots....

} else { shinyalert(paste0("Ensure Intervention date is atleast ", input$radio, " days less than current date"), type = "error")} )}

daattali commented 4 years ago

It looks like your code does not follow some basic shiny rectivity principles, which I would guess are the reason you're seeing strange results. You shouldn't define the outputs inside the observer. I recommend watching Joe Cheng's (shiny's author) video tutorials on reactivity https://resources.rstudio.com/shiny-developer-conference/shinydevcon-reactivity-joecheng-part-1-1080p