Is it possible to fill the choices (values) of ‘selectInput’ by calling a dataframe within a list? This would help in expediting the script as well as omitting lengthy choices.
I have a folder (choices) within my app.R folder. This folder contains 15 .xlsx (Excel) files, each of which contains two columns (x=id,y=value).
llist<-list.files(pattern=“*.xlsx”)
df_list<-lapply(list,readxl::read_excel)
This returns a list of data-frames (e.g.):
List of 2 $ 001.txt:'data.frame': 15 obs. of 2 variables: ..$ X: Factor w/ 50 levels ..$ Y: Factor w/ 50 levels $ 002.txt:'data.frame': 5 obs. of 2 variables ..$ X: Factor w/ 5 levels ..$ Y: Factor w/ 5 levels
When I attempt to call the values (second column of relevant dataframe) the app fails saying the choices must have a value.
selectInput (“state”, “States:”,
df_list[2][[2]]),
selectInput (“cnfd”, “Confidence”,
df_list[7][[2]])
...
str ( df_list[2])
df x: 1,2,3,4,5...50 y: Alaska, Alabama, Arkansas...
str(df_list[7]
df x: 1,2,3,4,5 y: ‘very low’, ‘low’, ‘moderate’, ‘high’, ‘very high’
Any ideas?
===========Update===============
Wanted to ensure I have the correct structure listed:
str(df_list)
List of 4
$ :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 5 obs. of 2 variables:
..$ id : num [1:5] 1 2 3 4 5
..$ value: chr [1:5] "very low" "low" "moderate" "high" ...
$ :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 45 obs. of 2 variables:
..$ id : num [1:45] 1 2 3 4 5 6 7 8 9 10 ...
..$ value: chr [1:45] "George Washington" "John Adams" "Thomas Jefferson" "James Madison" ...
$ :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 50 obs. of 2 variables:
..$ id : num [1:50] 1 2 3 4 5 6 7 8 9 10 ...
..$ value: chr [1:50] "Alabama" "Alaska" "Arizona" "Arkansas" ...
$ :Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 196 obs. of 2 variables:
..$ id : num [1:196] 1 2 3 4 5 6 7 8 9 10 ...
..$ value: chr [1:196] "Kabul" "Tirana" "Algiers" "Andorra la Vella"...
ShinyApp:
load('C:/Users/me/OneDrive/Documents/RProj/apps/data/dfenv.RData')
ui <- fluidPage(
titlePanel("Testing selectInput with list of data-frames"),
sidebarLayout(
sidebarPanel(
selectInput("state","States:",
df_list[3][2]),
selectInput("cty","Capital City:",
df_list[4][2]),
selectInput("cnf","Confidence:",
df_list[1][2]),
selectInput('potus',"President:",
df_list[2][2])
)))
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
The error:
Error in (function (choice, name) : All sub-lists in "choices" must be named.