I'm trying to make a shiny dashboard app in which the choices available in the dropdown menu are retrieved from a column in a reactive data object.
At the moment my code looks something like this:
library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(tidyverse)
data <- reactiveFileReader(
intervalMillis = 100000,
NULL,
filePath = 'Data\\data.csv',
readFunc = read.csv,
fileEncoding="UTF-8-BOM"
)
header <- dashboardHeader(title = "test")
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("plots", tabName = "plots"),
pickerInput('to','To:',
options = list(`actions-box` = TRUE, size = 10), multiple = TRUE,
choices = NULL)
)
)
fluid1 <- fluidRow(
box()
)
body <- dashboardBody(
tabItems(
tabItem(
tabName = 'plots', h2(fluid1)
)
)
)
ui <- dashboardPage(title = 'test', header, sidebar, body, skin='blue')
server <- function(input, output){
choices <- reactive({
data() %>%
select(to) %>%
unique()
})
observe({updatePickerInput('to',choices = choices())})
}
shinyApp(ui = ui, server = server)
And some sample data:
data <- data.frame(from = c('RCD', 'RCD', 'RCR', 'RCD', 'RCS', 'RCR', 'RCR', 'RCS', 'RCO', 'RCS'),
to = c('RCS', 'RCR', 'RCO', 'RCO', 'RCR', 'RCD', 'RCS', 'RCD', 'RCR', 'RCO'),
n = c(1,2,3,4,5,6,7,8,9,10))
What I expected was for this -
choices <- reactive({
data() %>%
select(to) %>%
unique()
})
to give me a list of unique values in the to
column of the data()
reactive object, which I could then pass to observe({updatePickerInput('to',choices = choices())})
Instead I get this error:
Warning: Error in : $ operator is invalid for atomic vectors
I'm quite new to using shiny so am having real problems troubleshooting this. Any help would be greatly appreciated