I am creating a shiny app for my data but my current code does not display the plot. Also based on column 8 onwards I also want to categorize my data under 2 checkboxes “Stage1” and “Stage2”. And based on a dropdown, date range and checkbox show subset/filter the data and show the plot. Stage1<-(mytest$status_2019|mytest$status_2020|mytest$status_2021|mytest$status_2022==1) Stage2<-(mytest$status_stage2_2019|mytest$status_stage2_2020|mytest$status_stage2_2021|mytest$status_stage2_2021|mytest$status_stage2_2022=1)
Here is mydata:
mydata<-structure(list(Id = c("DB-1", "DB-2", "DB-3", "DB-4", "DB-5",
"DB-6", "DB-7", "DB-9", "DB-11", "DB-12", "DB-13", "DB-14", "DB-15",
"DB-16", "DB-17", "DB-18", "DB-19", "DB-20", "DB-23", "DB-25",
"DB-26", "DB-27", "DB-28", "DB-29", "DB-30", "DB-31", "DB-32",
"DB-34", "DB-35", "DB-36", "DB-37"), examiner = c("Alex", "Alex",
"Alex", "Alex", "Alex", "Alex", "Kim", "Kim", "Kim", "Kim", "Kim",
"Alex", "Alex", "Jhon", "Jhon", "Jhon", "Jhon", "Jhon", "Jhon",
"Maymoon", "Maymoon", "Maymoon", "Maymoon", "Maymoon", "Mike",
"Mike", "Mike", "Mike", "Mike", "Mike", "Mike"), Relationship = c("sibling",
"mother", "self", "father", "self", "self", "self", "self", "self",
"mother", "self", "self", "self", "self", "mother", "father",
"self", "self", "mother", "self", "self", "self", "self", "sibling",
"father", "mother", "mother", "mother", "mother", "self", "father"
), application_date = c("12/4/18", "11/27/18", "11/30/18", "11/13/18",
"11/27/18", "11/13/18", "11/28/18", "2/26/19", "4/3/19", "1/15/19",
"4/3/19", "11/13/18", "2/25/19", "12/6/18", "1/15/19", "11/30/18",
"12/4/18", "11/20/18", "4/3/19", "2/25/19", "2/14/19", "12/6/18",
"3/14/19", "12/7/18", "1/10/19", "3/12/19", "3/22/19", "12/20/18",
"3/21/19", "4/5/19", "11/15/18"), gender = c("male", "female",
"male", "male", "male", "male", "female", "female", "female",
"female", "male", "female", "female", "female", "female", "male",
"male", "female", "female", "female", "male", "male", "female",
"male", "male", "female", "female", "female", "female", "female",
"male"), stage1_date = c("2/21/19 21:15", "1/10/19 21:45", "1/9/19 19:50",
"1/10/19 21:40", "1/10/19 21:45", "1/9/20 14:50", "1/10/19 21:45",
"3/15/19 16:50", "4/26/19 19:20", "3/21/19 18:21", "4/26/19 19:20",
"1/10/19 21:40", "3/15/19 16:50", "1/10/19 21:45", "3/21/19 18:21",
"1/31/19 20:25", NA, "1/10/19 21:45", "1/9/20 14:50", "7/30/19 15:10",
"3/4/19 16:30", NA, "4/8/19 12:40", "2/6/19 20:36", "1/31/19 20:25",
"5/1/19 18:05", "4/8/19 12:41", "1/17/19 19:26", "5/1/19 18:05",
NA, "1/10/19 21:45"), stage2_date = c(NA, NA, NA, NA, "5/11/21 17:50",
NA, "5/21/21 17:46", NA, "5/11/21 17:37", NA, "5/21/21 17:47",
"5/15/21 16:07", "5/16/21 16:07", NA, NA, NA, "5/11/21 17:52",
NA, NA, "5/14/21 16:07", "5/11/21 17:37", "5/11/21 17:52", NA,
NA, NA, NA, NA, NA, NA, "5/11/21 17:42", NA), status_2019 = c(1,
1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0,
1, 1, 1, 1, 1, 1, 1, 0, 1), status_2020 = c(0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0), status_2021 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
status_2022 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), status_stage2_2020 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), status_stage2_2021 = c(0,
0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1,
1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0), status_stage2_2022 = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), row.names = c(NA, -31L
), spec = structure(list(cols = list(Id = structure(list(), class = c("collector_character",
"collector")), Onboarded = structure(list(), class = c("collector_character",
"collector")), Relationship = structure(list(), class = c("collector_character",
"collector")), application_date = structure(list(), class = c("collector_character",
"collector")), gender = structure(list(), class = c("collector_character",
"collector")), stage1_date = structure(list(), class = c("collector_character",
"collector")), stage2_date = structure(list(), class = c("collector_character",
"collector")), status_2019 = structure(list(), class = c("collector_double",
"collector")), status_2020 = structure(list(), class = c("collector_double",
"collector")), status_2021 = structure(list(), class = c("collector_double",
"collector")), status_2022 = structure(list(), class = c("collector_double",
"collector")), status_stage2_2020 = structure(list(), class = c("collector_double",
"collector")), status_stage2_2021 = structure(list(), class = c("collector_double",
"collector")), status_stage2_2022 = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), delim = ","), class = "col_spec"), problems = <pointer: 0x7f7f0a7dc7c0>, class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"))
Here is my code:
library(shiny)
library(tidyverse)
library(dplyr)
library(ggplot2)
library(lubridate)
mydata <- read_csv("test.csv")
mydata$signed_date <- as.Date(mydata$signed_date, format = "%Y-%m-%d", optional=FALSE)
server <- function(input, output, session) {
#Summarize Data and then Plot
data <- reactive({
req(input$examiner)
mydata %>%
dplyr::filter(examiner %in% input$examiner ,
signed_date >= input$daterange[1] &
signed_date <= input$daterange[2]) %>%
group_by(relation) %>% summarize(Total = n())
})
output$selected_var <- renderText({
paste("You have chosen ", input$examiner, "between", input$Dates[1], "and", input$Dates[2])
})
#Plot
output$plot <- renderPlot({
g <- ggplot(data(), aes( y = Total, x = relation))
g + geom_bar(stat = "sum")
})
}
ui <- basicPage(
titlePanel("My Dashboard"),
helpText("Shows my data"),
selectInput(inputId = "examiner",
label = h3("Choose examiner"),
choices = c("None", as.character(mydata$examiner), selected = "None")),
dateRangeInput("Dates", h3("Select the Dates"), format="yyyy-mm-dd", start = "2018-04-01"),
mainPanel(
textOutput("selected_var"),
plotOutput("plot")
)
)
shinyApp(ui = ui, server = server)