0
votes

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:

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. This used to work before the inception of SelectizeInput was added. Any help is greatly appreciated.

1

1 Answers

2
votes

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