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))