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", "")
))))