闪亮-使用基于另一个输入的选项组更新selectizeInput输入

时间:2019-06-04 16:13:49

标签: r shiny

我正在尝试根据输入字段B的值更新输入字段A。

输入字段A是带有选项组的selectizeInput输入。我不知道如何访问输入字段A的值。下面的可复制示例r给出以下错误: “警告:错误:$运算符对于原子向量无效[无可用堆栈跟踪]”

iso<-c()
iso$Australia<-c("City 1","City 2")
iso$Colombia<-c("City 3","City 4")

ui <-fluidPage(sidebarLayout(
  sidebarPanel(

    selectizeInput('x1',label='sel1',choices =c(iso)), # In the UI the cities are sorted by Country
    selectizeInput('x2',label='sel2', choices =c("City 1","City 2","City 3","City 4")) #Options for the user to select
  ),
  mainPanel(
    verbatimTextOutput('values')
  )
), title = 'Options groups for select(ize) input')


server <-function(input, output, session) {
  selected<-reactive({selected<-input$x2})
  observeEvent(input$x2, {  #I would like for x1 to be updated with the same selection as x2
    print(selected())
    updateSelectizeInput( 'x1',selected =selected()) #This causes the mistake
  })}

shinyApp(ui = ui, server = server)

0 个答案:

没有答案
相关问题