Consider this app with three inputs and all are related to each other...
library(tidyverse)
library(shiny)
df <- mtcars %>%
split(.$vs)
ui <- fluidPage(
sidebarPanel(
radioButtons("no1", "Select", choices = names(df)),
selectInput("no2", "select", choices = NULL),
selectInput("no3", "select", choices = NULL)
),
mainPanel(plotOutput("plot"))
)
server <- function(input, output, session){
rv <- reactiveValues()
observe({
req(input$no1)
updateSelectInput(session,"no2", choices = df[[input$no1]]$cyl)
}, priority = 10)
observe({
rv$after_v1_v2 <- df[[input$no1]] %>% filter(cyl == input$no2)
}, priority = 9)
observe({
req(input$no1)
req(input$no2)
updateSelectInput(session,"no3", choices = rv$after_v1_v2$am )
}, priority = 8)
observe({
rv$after_v3 <- rv$after_v1_v2 %>% filter(am == input$no3)
}, priority = 7)
output$plot <- renderPlot({
Sys.sleep(2)
rv$after_v3 %>%
ggplot(aes(disp, hp)) +
geom_point()
})
outputOptions(output, "plot", priority = 1)
}
shiny::shinyApp(ui, server)
...how I prevent that the plot is rendered before the sidepanel inputs are updated. As you can see the priority parameters have no effect. The update should take place sequentially independent which input is changed e.g. no1 >> no2 >> no3 and then finally the plot.
I know there is a debounce()
, but I don't want to "manually" slow down the app.