简体   繁体   English

在反应式selectinput中为Shiny返回数据帧值

[英]Returning data frame value in reactive selectinput for Shiny

I'm trying to populate a dropdown for selectInput from a dataframe in a shiny application and can't seem to get it to work, here is a pared-down version: 我正在尝试从闪亮的应用程序中的数据帧填充selectInput的下拉列表,但似乎无法正常使用,这是一个简化的版本:

datapr<-data.frame(type=c("Analog", "Digital", "Mixed Signal","Analog"),process=c("Bipolar","CMOS","BiCMOS","Bipolar"),funct=c("BJT","Mux","Mux","Regulator"))

If I have that dataframe to start, my shiny application calls and uses it like so: 如果我要启动该数据框,那么我的闪亮应用程序将按以下方式调用和使用它:

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])
})

What I'm getting out is a number instead of the actual dataframe's entry and cannot seem to use unname(), unique(), factor(), as.list() or anything straight-forward to pull out the entry as is. 我得到的是一个数字而不是实际数据框的条目,并且似乎无法使用unname(),unique(),factor(),as.list()或任何直接提取该条目的方法。 This used to work before the inception of SelectizeInput was added. 在添加SelectizeInput之前,此方法曾经起作用。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

This worked for me: 这对我有用:

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]))
            })
    })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM