"Argument x is missing" for date-wise line graph

HI R Community,
I have created a shiny app where I need to track number of surveys happening daily. In the filter I have given dateInput. But the app does not work. I need multiple selection in date filter. So I have two issues:

  1. Multiple date selection and date does not appear properly.
  2. The line graph shows an error message (the screenshot I have attached below).
library(tidyverse)
library(shiny)
library(shinydashboard)
#> 
#> Attaching package: 'shinydashboard'
#> The following object is masked from 'package:graphics':
#> 
#>     box
data<-tibble::tribble(
            ~region,        ~date,
          "Hubli U", "02-04-2022",
          "Hubli R", "02-04-2022",
        "Dharwad R", "02-04-2022",
        "Dharwad U", "03-04-2022",
          "Hubli R", "04-04-2022",
          "Hubli U", "04-04-2022",
        "Dharwad R", "05-04-2022",
        "Dharwad U", "05-04-2022",
          "Hubli R", "05-04-2022",
          "Hubli U", "05-04-2022"
        )
str(data$date)
#>  chr [1:10] "02-04-2022" "02-04-2022" "02-04-2022" "03-04-2022" ...
data<-data %>% mutate(date=as.Date(date))


ui<-dashboardPage(
  skin = "green",
  dashboardHeader(title = "Test"),
  dashboardSidebar("Choose your inputs here",
                   selectInput("region","Select the Region",choices = data$region),
                   dateInput("date","Select the date",min = min(data$date),max = max(data$date))),
  dashboardBody(plotlyOutput("plot1"))
)
#> Error in plotlyOutput("plot1"): could not find function "plotlyOutput"
server<-function(input,output,session){
  num<-data %>% 
    group_by(date) %>% 
    summarise(number=n())

  output$plot1<-renderPlotly({
    ggplot(num(),aes(date,number))+
    geom_line(size=1.5)
  })
}

shinyApp(ui,server)
#> Error in force(ui): object 'ui' not found
Created on 2022-10-24 by the reprex package (v2.0.1)

Your dates as strings are not in a typical format, so you would have to specify the format like this:

data<-data %>% mutate(date=as.Date(date,"%d-%m-%Y"))

your main error/issue I think comes from your use of num() but num is not a function, nor a reactive function, its just the data data.frame that was grouped and summarised, i.e its a normal static data.frame

Oops, I forgot to add the reactive function. I have formatted the date as given by you. But the problem still persists. The date does not come in as required and neither does the plot.

library(tidyverse)
library(shiny)
library(plotly)
#> 
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#> 
#>     last_plot
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following object is masked from 'package:graphics':
#> 
#>     layout
library(shinydashboard)
#> 
#> Attaching package: 'shinydashboard'
#> The following object is masked from 'package:graphics':
#> 
#>     box
data<-tibble::tribble(
            ~region,        ~date,
          "Hubli U", "02-04-2022",
          "Hubli R", "02-04-2022",
        "Dharwad R", "02-04-2022",
        "Dharwad U", "03-04-2022",
          "Hubli R", "04-04-2022",
          "Hubli U", "04-04-2022",
        "Dharwad R", "05-04-2022",
        "Dharwad U", "05-04-2022",
          "Hubli R", "05-04-2022",
          "Hubli U", "05-04-2022"
        )

data<-data %>% mutate(date=as.Date(date,"%d-%m-%Y"))


ui<-dashboardPage(
  skin = "green",
  dashboardHeader(title = "Test"),
  dashboardSidebar("Choose your inputs here",
                   selectInput("region","Select the Region",choices = data$region),
                   dateInput("date","Select the date",min = min(data$date),max = max(data$date))),
  dashboardBody(plotlyOutput("plot1"))
)

server<-function(input,output,session){
  num<-reactive({
    data %>% 
      group_by(date) %>% 
      summarise(number=n()) %>% 
      filter(region %in% input$region)
  })
 
  output$plot1<-renderPlotly({
      plot1<-ggplot(num(),aes(input$date,number))+
      geom_line(size=1.5)
      
      ggplotly(plot1)
  })
}

shinyApp(ui,server)
#> PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.
Shiny applications not supported in static R Markdown documents
Created on 2022-10-24 by the reprex package (v2.0.1)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.