繁体   English   中英

根据另一个 updateSelectInput() 的值更新 updateselectInput()

[英]Update updateselectInput() based on values of another updateSelectInput()

在下面的应用程序中,我想更新我拥有的第二个updateSelectInput() ,以便在上传文件后排除在第一个updateSelectInput()中选择的值。 通常,该文件会上传用于 shiny 小部件值的数据集。

## app.R ##
library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    fileInput("file1", "Choose CSV File", accept = ".csv"),

    selectInput("col","Pick a column to change its name",
                choices = colnames(iris)[-c(1)]),
    selectInput("col2","Pick a column to change its name",
                choices = colnames(iris)[-c(1)])

  ),
  dashboardBody(
    
    )
)

server <- function(session,input, output) {
  
  observeEvent(input$file1, {
    updateSelectInput(session, "col", label = "Select target country", choices = colnames(iris)[-c(1)])
    ex_names <- colnames(iris)[-1]
    ex_names <- ex_names[! ex_names %in% input$col]
    updateSelectInput(session, "col2", label = "Select reference countries", choices =colnames(iris)[-c(1)] )  

    
  })
  
 
  
}

shinyApp(ui, server)

每次对col的选定值进行更改时,为col添加一个observeEvent将更新col2

observeEvent(input$col, {
    ex_names <- colnames(iris)[-1]
    ex_names <- ex_names[!ex_names %in% input$col]
    updateSelectInput(session, "col2", label="Select reference countries", choices=ex_names)  
  })

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM