Update select Input is super slow when nested under Observe

I have four dropdown in my app so far and three of them load menu options as the user selects one option in the first dropdown menu. My code below does that, but its super slow. Could you please help in making this faster?

function(input, output, session) {
  
 observeEvent(input$scheme,{
  if (input$scheme == "PMGSY") {
    updateSelectInput(session, "indicators", choices = PMGSY$variable)
    updateSelectInput(session, "year", choices = PMGSY$Year[!is.na(PMGSY$Year)])
    updateSelectInput(session, "vote", choices = PMGSY$`leading party`[!is.na(PMGSY$`leading party`)])
  }
  
  if (input$scheme == "NRDWP") {
    updateSelectInput(session, "indicators", choices = NRDWP$variable)
    updateSelectInput(session, "year", choices = NRDWP$Year)
    updateSelectInput(session, "vote", choices = NRDWP$`leading party`)
  }
  
  if (input$scheme == "Saubhagya") {
    updateSelectInput(session, "indicators", choices = Saubhagya$variable)
    updateSelectInput(session, "year", choices = Saubhagya$Year)
    updateSelectInput(session, "vote", choices = Saubhagya$`leading party`)
  }
  
  if (input$scheme == "Swachh Bharat") {
    updateSelectInput(session, "indicators", choices = sb$variable)
    updateSelectInput(session, "year", choices = sb$Year)
    updateSelectInput(session, "vote", choices = sb$`leading party`)
  }
  
  if (input$scheme == "MGNREGA") {
    updateSelectInput(session, "indicators", choices = MGNREGA$variable)
    updateSelectInput(session, "year", choices = MGNREGA$Year)
    updateSelectInput(session, "vote", choices = MGNREGA$`leading party`)
  }
  
  
  })

}

ui.r

library(shiny)
source("global.R")

ui <- fluidPage(
  
  mainPanel(
    fluidRow(
    column (width = 10,
            selectInput('scheme', 'Schemes', 
                        choices = c("PMGSY", "MGNREGA", "Swachh Bharat", "Saubhagya", "NRDWP"),
                        selected = "PMGSY"),
            
            selectInput('indicators', 'Indicator', ""),
                
            selectInput("year", 'Year', ""),
                
            selectInput("vote", "Filter districts by party leading in 2014 vote share", "")
                
            ))))


Dear @shreya2105 I think the function you are looking for is observe.

Just change your observeEvent(input$scheme,{ to observe({.

I think it will fast your app's reaction

Thanks @LucasAlmeida for replying. I tried 'observe', it is still super slow. Is there anything else I can use to switch between multiple datasets?

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.