首页 > 解决方案 > Shiny - 通过 updateSelectInput() 在 selectInput() 中更改“选择”

问题描述

我正在尝试根据第一个 selectInput() 中的选择更改第二个 selectInput() 中的选择。这是我的代表。提前感谢您的帮助。

    library(shiny)
    ui <- fluidPage(
      tabPanel("tbls",
        selectInput("tab1",label="Pick a table:",choices=c("a","b","c")),
        selectInput("cht1",label="Pick a time series:",choices=c("d","e","f"))
      )
    )
    server <- function(input,output,session) {
      Nchoices <- reactive({case_when(
        input$tab1=="a" ~c("d","e","f"),
        input$tab1=="b" ~c("g","h","i"),
        input$tab1=="c" ~c("j","k","l")
      )}) 
      observeEvent(input$tab1,{updateSelectInput(session,input$cht1,
        label="Pick a time series:",choices=Nchoices(),selected=NULL)})
      observe(print(Nchoices()))
    }
    shinyApp(ui, server)

标签: rshiny

解决方案


推荐阅读