2

I am trying to write a shiny app that loads several data frames. The data frames for my plots all work very well, but one data.frame which I want to use as a list of options in a dropdown menu does not load. If I load the frame seperately in the R session, everything works, but if I only run the shiny app, the selectors won't update.

library(shiny)

ui <- fluidPage(
               #...
               selectInput("mats", "Text",
                           selectors)
               # ...
)

server <- function(input, output){
     # ...
     df1=read.csv("./data/file.csv", sep=";", head=T, stringsAsFactors = F)
     df1$choices=as.character(df1$choices)
     selectors=c("All", df1$choices)
     #...
}

shinyApp(ui = ui, server = server)

I think, I need the selectors in the server function, so I loaded the data frame there together with my other data frames. Is that the right place and what do I need to do to get this running?

Best

Peter
  • 355
  • 1
  • 8
  • 23

1 Answers1

1

There is a number of problems with your code:

  1. Following the documentation, choices in selectInput should be a list.
  2. If you want to create an element that would be available across the ui and server please consider reading the linked article on scoping rules in Shiny and defining your object in global.R.

With respect to the 1st point, if your intention is to use a data.frame column as a base for menu selection, you can apply the following transformation:

my_new_list <- split(df$id, df$subject)

as provided in this answer by @user3710546 to a similar question that I've asked in past.


Side note

Please consider having a look at the discussion on making a reproducible example in R. If you care to redo your example using some publicly available data, it will be easy to produce a solution. If I understood the problem correctly, you want to use data.frame column as a base for UI element, which is not difficult on its own.

.

Community
  • 1
  • 1
Konrad
  • 17,740
  • 16
  • 106
  • 167