我有下面的shiny
应用程序与4输入.他们包含的mtcars
数据集的所有变量.现在,我想如果一个值选择,例如在一个输入(例如mpg在第一)这个值不能选择在任何其他输入.所以每次这4输入将有一个不同的值选择.
library(shiny)
library(shinydashboard)
choices <- c("Pop", "RC", "RT","R4")
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
selectInput("Pr", "Select the price for analysis", choices = choices, multiple = F, selected = choices[1]),
selectInput("Pr2", "Select the price for analysis", choices = choices, multiple = F, selected = choices[2]),
selectInput("Pr3", "Select the price for analysis", choices = choices, multiple = F, selected = choices[3]),
selectInput("Pr4", "Select the price for analysis", choices = choices, multiple = F, selected = choices[4])
),
dashboardBody()
)
server <- function(input, output, session) {
observeEvent(input$Pr, {
updateSelectInput(session, "Pr2", choices = choices[!choices %in% input$Pr])
})
observeEvent(input$Pr3, {
updateSelectInput(session, "Pr2", choices = choices[!choices %in%input$Pr3])
})
observeEvent(input$Pr4, {
updateSelectInput(session, "Pr2", choices = choices[!choices %in%input$Pr4])
})
observeEvent(input$Pr2, {
updateSelectInput(session, "Pr", choices = choices[!choices %in% input$Pr2])
})
observeEvent(input$Pr3, {
updateSelectInput(session, "Pr", choices = choices[!choices %in% input$Pr3])
})
observeEvent(input$Pr4, {
updateSelectInput(session, "Pr", choices = choices[!choices %in% input$Pr4])
})
observeEvent(input$Pr, {
updateSelectInput(session, "Pr3", choices = choices[!choices %in% input$Pr])
})
observeEvent(input$Pr2, {
updateSelectInput(session, "Pr3", choices = choices[!choices %in% input$Pr2])
})
observeEvent(input$Pr4, {
updateSelectInput(session, "Pr3", choices = choices[!choices %in% input$Pr4])
})
observeEvent(input$Pr, {
updateSelectInput(session, "Pr4", choices = choices[!choices %in% input$Pr])
})
observeEvent(input$Pr2, {
updateSelectInput(session, "Pr4", choices = choices[!choices %in% input$Pr2])
})
observeEvent(input$Pr3, {
updateSelectInput(session, "Pr4", choices = choices[!choices %in% input$Pr3])
})
}
shinyApp(ui, server)
字符串
1条答案
按热度按时间bqujaahr1#
试试这个
字符串