R 选择输入';选择全部';等级制度
编辑:添加示例数据 我想为多个SelectInputs添加一个“全选”选项。因此,如果我选择“所有”国家,第二个selectInput下拉列表将显示所有地区,如果我选择特定国家,我可以选择该国家的“所有”地区或特定地区 选择国家级别的所有工作,但我不知道如何将其应用到第二个区域级别 如果可能的话,我想在没有pickerInPut的情况下这样做 数据:R 选择输入';选择全部';等级制度,r,shiny,selectinput,R,Shiny,Selectinput,编辑:添加示例数据 我想为多个SelectInputs添加一个“全选”选项。因此,如果我选择“所有”国家,第二个selectInput下拉列表将显示所有地区,如果我选择特定国家,我可以选择该国家的“所有”地区或特定地区 选择国家级别的所有工作,但我不知道如何将其应用到第二个区域级别 如果可能的话,我想在没有pickerInPut的情况下这样做 数据: Country也许pickerInput可以满足您的需求,如下例所示 ui = fluidPage( titlePanel(title=div
Country也许pickerInput
可以满足您的需求,如下例所示
ui = fluidPage(
titlePanel(title=div(img(src="YBS.png", height = 140, width = 140), "This is a Test")),
sidebarLayout(
sidebarPanel(
uiOutput("organt"),
uiOutput("cellt")
),
mainPanel(
tableOutput("MegaData")
)
)
)
server = function(input, output, session) {
df1 <- veteran
MegaP <- df1 %>% mutate(Organ=ifelse(trt==1,"Lung","Skin"))
output$organt <- renderUI({
selectInput("OrganT",
label = "Organ",
choices = unique(MegaP$Organ),
multiple = T,
selected = "All")
})
MegaP1 <- reactive({
data <- subset(MegaP, Organ %in% req(input$OrganT))
})
output$cellt <- renderUI({
req(MegaP1())
mychoices <- as.character(unique(MegaP1()$celltype))
pickerInput(inputId = "Cell",
label = "Cell Line",
choices = mychoices,
multiple = TRUE,
options = list(`actions-box` = TRUE)
)
})
selectedData <- reactive({
req(MegaP1(),input$Cell)
data <- subset(MegaP1(), celltype %in% input$Cell)
})
output$MegaData = renderTable({
selectedData()
})
}
shinyApp(ui = ui, server = server)
ui=fluidPage(
titlePanel(title=div(img(src=“YBS.png”,高度=140,宽度=140),“这是一个测试”),
侧边栏布局(
侧栏面板(
uiOutput(“organt”),
UIT输出(“cellt”)
),
主面板(
表格输出(“兆数据”)
)
)
)
服务器=功能(输入、输出、会话){
df1我尝试了这个,但在第二个下拉列表中仍然没有给我“全部”选项。请尝试更新的代码。您可以将selectInput移动到服务器端。
ui<- dashboardPage(
dashboardHeader(title = "Performance"),
dashboardSidebar(selectizeInput(inputId = "Country", label = "Country", choices = c('All', list)),
(selectizeInput(inputId = "Region", label = "Region", choices = c('All', list2)))),
dashboardBody(
fluidRow(
box(valueBoxOutput(outputId = "Total", width = 12), title = "Total"),
box(valueBoxOutput(outputId = "Value", width = 12), title = "Value"),
)
),
)
server <- function(input, output, session) {
Test <- reactive({
if(input$Country == 'All') {
Joined_data %>%
filter(`Contract Locality` == input$Locality)
} else {
Joined_data %>%
filter(`Country` == input$Country, `Region` == input$Region)
}})
output$Total <- renderValueBox({
valueBox(Test() %>%
tally(),
req(input$Country)
})
output$Value <- renderValueBox({
valueBox(Test() %>%
summarise("Annualised_Value" = sum(`Value (Annualised)`)) %>%
prettyNum(big.mark = ","),
req(input$Country)
})
Country.choice <- reactive({
Joined_data %>%
filter(Country == input$Country %>%
pull(Region)
})
observe({
updateSelectizeInput(session, "Region", choices = Country.choice())
})
}
shiny::shinyApp(ui=ui,server=server)
ui = fluidPage(
titlePanel(title=div(img(src="YBS.png", height = 140, width = 140), "This is a Test")),
sidebarLayout(
sidebarPanel(
uiOutput("organt"),
uiOutput("cellt")
),
mainPanel(
tableOutput("MegaData")
)
)
)
server = function(input, output, session) {
df1 <- veteran
MegaP <- df1 %>% mutate(Organ=ifelse(trt==1,"Lung","Skin"))
output$organt <- renderUI({
selectInput("OrganT",
label = "Organ",
choices = unique(MegaP$Organ),
multiple = T,
selected = "All")
})
MegaP1 <- reactive({
data <- subset(MegaP, Organ %in% req(input$OrganT))
})
output$cellt <- renderUI({
req(MegaP1())
mychoices <- as.character(unique(MegaP1()$celltype))
pickerInput(inputId = "Cell",
label = "Cell Line",
choices = mychoices,
multiple = TRUE,
options = list(`actions-box` = TRUE)
)
})
selectedData <- reactive({
req(MegaP1(),input$Cell)
data <- subset(MegaP1(), celltype %in% input$Cell)
})
output$MegaData = renderTable({
selectedData()
})
}
shinyApp(ui = ui, server = server)
dat <- data.frame(Country, Region, Value, Outcomes, Outputs, Risk)
list<- unique(dat$Country)
list2 <- unique(dat$`Region`)
app <- shinyApp(
ui = shinyUI(
pageWithSidebar(
headerPanel("Simple Test"),
sidebarPanel(
selectInput("cy", "Country", choices = c("All", list )),
selectInput("rg", "Region", choices = c("All", list2 ))
),
mainPanel(
DTOutput("out")
)
)
),
server = function(input, output, session) {
filtered <- reactive({
rows <- (input$cy == "All" | dat$Country == input$cy) &
(input$rg == "All" | dat$Region == input$rg)
dat[rows,,drop = FALSE]
})
output$out <- renderDT(filtered())
}
)