简体   繁体   中英

Shiny selectInput from column DF

Currently i am working on my own shinydashboard. And i would like to ask you for help. I would like to show Data_Location()$Address in my inputbox that is corresponding to Data_Location()$Location_skey . Normally you can do it like this:

selectInput("KPI", "Choose a KPI:", choices = c("Aantal Sessies Aansluiting"="AantalSessiesAansluiting",
                                                                               "Aantal Unieke RFIDS Aansluitingg"="AantalUniekeRFIDsAansluiting",
                                                                               "Beschikbare Dagen Aansluiting"="BeschikbareDagenAansluiting",selected="")

The difference is that I want to use a dataframe column.

head(Data_Location()$Location_skey)
[1] -1  
[2]  1  
[3]  2  
[4]  3  
[5]  4 

head(Data_Location()$Address)
[1] onbekend
[2] Putstraat 86
[3] 1e De Riemerstraat 1   
[4] Van Spaenstraat 23     
[5] Suze Groeneweglaan 323 

selectInput("location", "Selected a charge point",choices =c("",Data_Location()$Location_skey), selected="")

I would like to thank you for reading this post and I would be very pleased if you could help me out.

Thanks!

I think this is what you want:

library(shiny)

ui <- fluidPage(
    selectInput("sip","select",choices=1:3)
) 

server <- function(input,output,session){
  df <- data.frame(cnames=c("a","b","c"),keys=c(1,2,3))
  chlst <- df$keys
  names(chlst) <- df$cnames
  updateSelectInput(session,"sip",label="label",choices=chlst)
} 
shinyApp(ui,server)

yielding:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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