I am facing an issue in getting the output of selectizeInput to update the uploaded csv data. The specific code block having issue is
observeEvent(input$Go, {
tmp <- values$df_data
output$Grp = renderUI({
lvls <- tmp %>%
pull(Group) %>%
levels
selectizeInput('group', 'Groups', choices = lvls, selected = lvls[1], multiple = FALSE)
})
tmp1 <- tmp %>%
filter(Group == "A") # need to change here by updating the value from input$Grp
values$df_data <- tmp1
})
The 'Group' column is filtered with a hard coded value. My intention is to make it dynamic by getting the values of "Grp". Image below shows the issue
The full code is below
library(shinydashboard)
library(shiny)
library(dplyr)
library(tidyr)
ui = dashboardPage(
dashboardHeader(),
dashboardSidebar(
width = 200,
sidebarMenu(
menuItem("File Upload", icon = shiny::icon("table")),
fileInput('datafile', 'Choose CSV file',
accept=c('text/csv', 'text/comma-separated-values,text/plain')),
uiOutput('Grp'),
actionButton("Go","Subset Data"))
),
dashboardBody( fluidPage(
titlePanel("Data Table"),
sidebarLayout(
tabPanel("tab",
div( id ="Sidebar",sidebarPanel(
))),
mainPanel(
DT::dataTableOutput("tableOut")
)
)
)
)
)
server = function(input, output, session) {
values <- reactiveValues(df_data = NULL)
observeEvent(input$datafile, {
values$df_data <- read.csv(input$datafile$datapath)
})
observeEvent(input$Go, {
tmp <- values$df_data
output$Grp = renderUI({
lvls <- tmp %>%
pull(Group) %>%
levels
selectizeInput('group', 'Groups', choices = lvls, selected = lvls[1], multiple = FALSE)
})
tmp1 <- tmp %>%
filter(Group == "A") # need to change here by updating the value from input$Grp
values$df_data <- tmp1
})
output$tableOut <- DT::renderDataTable({
DT::datatable(values$df_data)
})
}
shinyApp(ui = ui, server = server)
I am uploading .csv file. The below data is similar to the one I have.
set.seed(12345)
data <- data.frame(DATE = rep(seq(as.Date("2014-01-01"), length.out = 200,
by = "week"), each = 4), Group = rep(c("A", "B", "C", "D"), each = 200),
ValueColumn = rnorm(800))
This problem does not seem to be isolated to selectizeInput
but pertains to any new data that you are trying to get your Shiny app to "see". Here are a couple things to try:
_cache
directories in the root of your shiny server, then try to load again. If there is no difference,touch
the .csv
files (or make an edit if on Windows, to get a new timestamp) and then try to load again. If there is no difference,sudo systemctl restart shiny-server
where the last argument is the name of your shiny server (default is shiny-server
)This last solution is the one that worked most reliably for me -- it is #2 from this document (Shiny app does not reflect changes in update RData file) -- to restart the shiny server from the command line. This worked reliably and routinely. The other ideas in this solution did not work on my machine so must be dependent on your server or client specifications.
The second thing that worked for me was to use reactiveTimer
(https://shiny.rstudio.com/reference/shiny/0.14/reactiveTimer.html).