1
我想根據我加載的數據框創建帶有選項的selectInput。這些選項應該分組,如下例所示。我知道如何在完全寫出時做到這一點,但是,我希望下拉列表能夠自動化,以便在更改數據框時自動更改。我可能會更改組的列表或每個組內的指標列表。在SelectInput(RShiny)中動態填充選項的分組列表
DD <- data.frame(group=c("Diagnosis","Diagnosis", "Treatment", "Treatment", "Outcome", "Outcome", "Outcome"),
Indicator=LETTERS[1:7])
> DD
group Indicator
1 Diagnosis A
2 Diagnosis B
3 Treatment C
4 Treatment D
5 Outcome E
6 Outcome F
7 Outcome G
這是我找的風格:
runApp(
list(
ui = fluidPage(
sidebarLayout(
sidebarPanel(
selectInput(inputId = "IND",
label = "Select indicator:",
choices = list("Diagnosis" = c("A", "B"),
"Treatment" = c("C", "D"),
"Outcome" = c("E", "F", "G")))
, width = 3),
mainPanel(
)
)
)
, server = function(input, output, session){
}
)
)
真棒簡單的解決方案!大! – Luc