Hi,
I have a dataset where I have to monitor the number of surveys done each day. Here I have a variable "submission_date" with a time stamp attached to it. But when I give the date filter in the app, it does not work. I want a line graph to appear according to the date. How can I achieve this?
library(tidyverse)
library(shiny)
library(shinydashboard)
#>
#> Attaching package: 'shinydashboard'
#> The following object is masked from 'package:graphics':
#>
#> box
library(janitor)
#>
#> Attaching package: 'janitor'
#> The following objects are masked from 'package:stats':
#>
#> chisq.test, fisher.test
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
data<-tibble::tribble(
~submission_date, ~enumerator, ~en_id,
"2022-07-03 09:49:30", "Gandhi", "BEN001",
"2022-07-03 11:40:04", "Nehru", "BEN002",
"2022-07-03 11:48:58", "Patel", "BEN003",
"2022-07-03 13:10:37", "Gandhi", "BEN001",
"2022-07-03 13:12:28", "Nehru", "BEN002",
"2022-07-04 13:12:08", "Patel", "BEN003",
"2022-07-04 13:12:20", "Gandhi", "BEN001",
"2022-07-04 13:12:30", "Nehru", "BEN002",
"2022-07-04 13:12:30", "Patel", "BEN003",
"2022-07-08 14:45:23", "Gandhi", "BEN001",
"2022-07-08 14:45:24", "Nehru", "BEN002",
"2022-07-08 15:25:03", "Patel", "BEN003",
"2022-07-08 15:25:24", "Gandhi", "BEN001",
"2022-07-08 15:25:46", "Nehru", "BEN002",
"2022-07-08 15:25:51", "Patel", "BEN003",
"2022-07-08 15:25:55", "Gandhi", "BEN001",
"2022-07-08 15:25:59", "Nehru", "BEN002",
"2022-07-08 15:26:08", "Patel", "BEN003"
)
ui<-dashboardPage(
dashboardHeader(title = "Test"),
dashboardSidebar("Choose your inputs here",
selectInput("date","select the date",choices = data$submission_date)),
dashboardBody(
tabPanel(plotlyOutput("plot1"))
)
)
server<-function(input,output,session){
filtered<-reactive({
data %>%
filter(submission_date %in% input$date) %>%
group_by(submission_date) %>%
summarise(number_of_surveys=n())
})
output$plot1<-renderPlotly({
graph1<-ggplot(filtered(),aes(submission_date,number_of_surveys))+
geom_line(size=1.5)+
theme_minimal()+
labs(title = "Day-wise number of surveys",
x="Date of survey",
y="# of surveys")
ggplotly(graph1)
})
}
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-17 by the reprex package (v2.0.1)