2

I'm trying to create a shiny dashboard that allows the user to select a csv file. The file contains only two columns that are order number and dateCreated. I want the user to be able to in addition, select the date range that they desire and get a summary count statistic.

So far my code is as follows:

library(shiny) library(plotly) library(colourpicker) library(ggplot2) ui <- fluidPage( titlePanel("Case Referrals"), sidebarLayout( sidebarPanel( fileInput("file", "Select a file"), sliderInput("period", "Time period observed:", min(data()[, c('dateCreated')]), max(data()[, c('dateCreated')]), value = c(min(data[, c('dateCreated')]),max(data()[, c('dateCreated')]))) ), mainPanel( DT::dataTableOutput("table") ) ) ) # Define the server logic server <- function(input, output) { # file input input_file <- reactive({ if (is.null(input$file)) { return("") } }) # summarizing data into counts data <- input_file() data <- subset(data, dateCreated >= input$period[1] & dateCreated <= input$period[2]) output$table <- DT::renderDataTable({ data }) } shinyApp(ui = ui, server = server) 

I get an error message saying:

Error in data()[, c("dateCreated")] : incorrect number of dimensions

Can anyone help me understand what the problem might be and/or provide a better framework for doing this? And to be clear in the csv file, the createDate variable is broken down into individual days for when the order was placed.

Thank you!

1
  • 1
    Could you share an example of a .csv you want to upload? Commented Nov 29, 2021 at 21:41

1 Answer 1

4

I added comments to the faulty steps.

library(shiny) ui <- fluidPage( titlePanel("Case Referrals"), sidebarLayout( sidebarPanel( fileInput("file", "Select a file"), # you cannot call data() in your ui. # You would have to wrap this in renderUI inside of your server and use # uiOutput here in the ui sliderInput("period", "Time period observed:", min = 1, max = 10, value = 5) ), mainPanel( DT::dataTableOutput("table") ) ) ) # Define the server logic server <- function(input, output) { input_file <- reactive({ if (is.null(input$file)) { return("") } # actually read the file read.csv(file = input$file$datapath) }) output$table <- DT::renderDataTable({ # render only if there is data available req(input_file()) # reactives are only callable inside an reactive context like render data <- input_file() data <- subset(data, dateCreated >= input$period[1] & dateCreated <= input$period[2]) data }) } shinyApp(ui = ui, server = server) 
Sign up to request clarification or add additional context in comments.

6 Comments

Thank you. This helps resolve my issue. Is there a way to change the slider to be in a date format?
If so, please accept. Fpr date inputs see here
sorry, forgot to ask... how do i get the aggregated counts for the date range selected? I tried: data <- data %>% group_by(dateCreated) %>% summarise(case_count = n()) but it doesn't work.
please ask a different question for a different problem
It was part of my original question. I need to provide count statistics for the data range selected by the user.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.