我正在尝试从闪亮的应用程序中的数据框填充selectInput的下拉列表,似乎无法使其工作,这是一个简化的版本:
datapr<-data.frame(type=c("Analog", "Digital", "Mixed Signal","Analog"),process=c("Bipolar","CMOS","BiCMOS","Bipolar"),funct=c("BJT","Mux","Mux","Regulator"))
如果我要启动该数据帧,我的闪亮应用程序会调用并使用它:
ui.R
shinyUI({
selectInput("type",h4("Type:"),list("Analog","Digital","Mixed Signal"))
selectInput("process",h4("Process:"),"")
})
server.R
shinyServer(function(input,output,session){
observe({updateSelectInput(session,"process",choices=datapr$process[datapr$type==input$type])
})
我得到的是一个数字而不是实际数据帧的条目,似乎无法使用unname(),unique(),factor(),as.list()或任何直接提取条目原样。这已经在添加SelectizeInput开始之前工作了。任何帮助是极大的赞赏。
答案 0 :(得分:2)
这对我有用:
ui.R
library(shiny)
shinyUI(fluidPage(
selectInput("type",h4("Type:"),list("Analog","Digital","Mixed Signal")),
selectInput("process",h4("Process:"),"")
))
server.R
library(shiny)
datapr<-data.frame(type=c("Analog", "Digital", "Mixed Signal","Analog"),
process=c("Bipolar","CMOS","BiCMOS","Bipolar"),
funct=c("BJT","Mux","Mux","Regulator"))
shinyServer(function(input,output,session){
observe({
updateSelectInput(session,"process",
choices=as.character(datapr$process[datapr$type==input$type]))
})
})