根据另一个 updateSelectInput() 的值更新 updateselectInput()
Update updateselectInput() based on values of another updateSelectInput()
在下面的应用程序中,我想更新第二个 updateSelectInput()
,以便在上传文件后排除在第一个 updateSelectInput()
中选择的值。通常,该文件会上传用于闪亮小部件值的数据集。
## 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)
})
在下面的应用程序中,我想更新第二个 updateSelectInput()
,以便在上传文件后排除在第一个 updateSelectInput()
中选择的值。通常,该文件会上传用于闪亮小部件值的数据集。
## 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)
})