【发布时间】:2020-09-14 18:41:16
【问题描述】:
我有下面闪亮的仪表板,我从pickerInput() 中选择"Select Database/s",如果我将显示Sepal.Length 的值(如果仅选择此选项)或Sepal.Width(如果仅选择此选项)或两者如果两者都选择选择。是否可以在同一个uiOutput("fnamesid") 中实现它而不必使用两个不同的uiOutput()?
library(shiny)
library(shinydashboard)
library(shinyWidgets)
ui <- dashboardPage(
header = dashboardHeader(title = "My dashboard"),
sidebar = dashboardSidebar(
uiOutput("dbs"),
uiOutput("fnamesid")
),
body = dashboardBody(
)
)
server <- function(input, output, session) {
output$dbs<-renderUI({
pickerInput("DB", "Select Database/s",
choices = c("Sepal.Length","Sepal.Width"),
multiple = T,options = list(`actions-box` = TRUE),
selected = "Sepal.Length")
})
output$fnamesid<-renderUI({
if("Sepal.Length"%in% input$DB){
pickerInput("sn", "Select sn_ID for x-axis",
choices = unique(iris$Sepal.Length),
multiple = T,options = list(`actions-box` = TRUE),
selected = head(unique(iris$Sepal.Length)))
}
else if("Sepal.Width"%in% input$DB){
pickerInput("sn2", "Select sn_ID for x-axis",
choices = unique(iris$Sepal.Width),
multiple = T,options = list(`actions-box` = TRUE),
selected = head(unique(iris$Sepal.Width)))
}
else if("Sepal.Length"%in% input$DB&"Sepal.Width"%in% input$DB){
pickerInput("sn", "Select sn_ID for x-axis",
choices = unique(iris$Sepal.Length),
multiple = T,options = list(`actions-box` = TRUE),
selected = head(unique(iris$Sepal.Length)))
pickerInput("sn2", "Select sn_ID for x-axis",
choices = unique(iris$Sepal.Width),
multiple = T,options = list(`actions-box` = TRUE),
selected = head(unique(iris$Sepal.Width)))
}
})
}
shinyApp(ui, server)
【问题讨论】: