有光泽可以自动过滤UI页面中的数据吗?比如选择网站,标题数据按网站自动过滤?
sidebarLayout(
sidebarPanel(
selectInput("Site", "Choose a Site:",
choices = site),
selectInput("Title", "Choose a Title:",
choices = title,multiple=TRUE),
selectInput("Job Category", "Choose a Job category:",
choices = job_category,multiple=TRUE),
>
#-----Raw data--------
Site Title Job_Category
1 Wuxi Sr Manager Management
2 Wuxi Manager Management
3 Wuxi Sr Manager Management
4 Suzhou Manager Management
5 Wuxi Analyst II Professional
6 Wuxi Director Management
7 Wuxi Manager Management
8 Wuxi Staff Analyst Professional
9 Wuxi Sr Team Lead Management
10 Wuxi Manager Management
11 Wuxi Sr Administrator Professional
12 Suzhou Manager Management
13 Suzhou Sr Analyst Professional
14 Suzhou Sr Analyst Professional
15 Suzhou Staff Analyst Professional
16 Suzhou Sr Analyst Professional
17 Wuxi Staff Analyst Professional
18 Suzhou Analyst II Professional
19 Suzhou Analyst II Professional
20 Wuxi Sr Administrator Professional
答案 0 :(得分:0)
您可以使用renderUI
在selectinput
中创建server.R
个变量。有observe updateSelectInput based on first selection例外,您可以在updateSelectInput
语句中使用observer
来更新selectInput
但是我不知道如何根据它选择所有变量。以下是基于第一种方法的工作示例。请注意,我根据您提供的输入创建了示例数据。
library(shiny)
Site <- NULL
Title <- NULL
Job_Category <- NULL
for (i in 1:50)
{
Site[i] <- sample(c("Wuxi","Suzhou","Other site"))[1]
Title[i] <- sample(c("Sr Manager","Manager","Director", "Analyst II","Sr Administrator"))[1]
Job_Category[i] <- sample(c("Management","Professional"))[1]
}
ui =fluidPage(
tabPanel("Testing",
sidebarPanel(
selectInput("Site", "Choose a Site:", choices = c(Site)),
uiOutput("varselect2"),uiOutput("varselect3"))))
server = function(input, output, session){
output$varselect2 <- renderUI({
cols <- Title[Site %in% input$Site]
selectInput("vars", "Select Title:",choices=cols, selected=cols, multiple=T)
})
output$varselect3 <- renderUI({
cols2 <- Job_Category[Site %in% as.character(input$Site) & Title %in% input$vars]
selectInput("vars2", "Select Job category:",choices=cols2, selected=cols2, multiple=T)
})
}
runApp(list(ui = ui, server = server))