2
我想從字段的唯一值創建selectInput下拉列表,而不必枚舉全部。如何做到這一點?閃亮的R獨特的字段值作爲下拉項目
舉例來說,在這個簡單的例子,如果我有以下data.frame,state_data:
State V1
MA 1
MA 2
MA 54
VA 1
NC 4
VA 4
NC 20
我想的下拉選項是MA,VA,NC,然後在服務器端我會希望它對應於data.frame的選定子集。
UI.r
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("State Data"),
sidebarPanel(
selectInput("variable","State:",
list(State)),
),
mainPanel()
))
Server.r
library(shiny)
state_data <- read.csv("dummy.csv",header=T)
State <- factor(state_data$state)
State <- levels(State)
shinyServer(function(input, output) {
})
看這個,動態UI http://rstudio.github.io/shiny/tutorial/#dynamic-ui – Ananta