diff --git a/R/app_server.R b/R/app_server.R index afd75f0..0100fcd 100644 --- a/R/app_server.R +++ b/R/app_server.R @@ -20,7 +20,7 @@ app_server <- function( input, output, session ) { db_data <- dplyr::tbl(pool, dbplyr::in_schema("TEXT_MINING", get_golem_config("trust_name"))) %>% - tidy_all_trusts(conn = pool, trust_id = get_golem_config("trust_name")) + tidy_all_trusts(conn = pool) # vector of sentiment names @@ -30,6 +30,12 @@ app_server <- function( input, output, session ) { dplyr::pull() %>% sort() + # find out if there is data in the table + + data_exists <- db_data %>% + dplyr::tally() %>% + dplyr::pull(n) > 0 + # store values of demographics and location_1 from last 3 years interpolate_date <- Sys.Date() @@ -47,11 +53,9 @@ app_server <- function( input, output, session ) { output$filter_location_1 <- renderUI({ - if(!isTruthy(get_golem_config("location_1"))){ + req(get_golem_config("location_1")) + req(data_exists) - return() - } - location_1_choices <- date_filter() %>% dplyr::distinct(location_1) %>% dplyr::mutate(location_1 = dplyr::na_if(location_1, "Unknown")) %>% @@ -69,12 +73,9 @@ app_server <- function( input, output, session ) { output$filter_location_2 <- renderUI({ - if(!isTruthy(get_golem_config("location_2"))){ - - return() - } - - + req(get_golem_config("location_2")) + req(data_exists) + location_2_choices <- date_filter() if(isTruthy(input$select_location_1)){ # filter by location_1 if exists @@ -99,11 +100,9 @@ app_server <- function( input, output, session ) { output$filter_location_3 <- renderUI({ - if(!isTruthy(get_golem_config("location_3"))){ + req(get_golem_config("location_3")) + req(data_exists) - return() - } - location_3_choices <- date_filter() if(isTruthy(input$select_location_1)){ # filter by location_1 if exists @@ -150,6 +149,7 @@ app_server <- function( input, output, session ) { dplyr::filter(date > !!input$date_range[1], date < !!input$date_range[2]) }) + filter_data <- reactive({ if(get_golem_config("trust_name") == "demo_trust"){ diff --git a/R/tidy_data.R b/R/tidy_data.R index 614edb7..4248569 100644 --- a/R/tidy_data.R +++ b/R/tidy_data.R @@ -12,13 +12,23 @@ #' Chris Beeley #' @section Last updated date: #' 2021-04-25 -tidy_all_trusts <- function(data, conn, trust_id) { +tidy_all_trusts <- function(data, conn) { - data %>% - dplyr::mutate(category = dplyr::case_when( - is.null(comment_txt) ~ NA_character_, - is.na(comment_txt) ~ NA_character_, - comment_txt %in% c("NULL", "NA", "N/A") ~ NA_character_, - TRUE ~ category - )) + # this line only works if there is data in the table + + if(data %>% + dplyr::tally() %>% + dplyr::pull(n) > 0) { + + data %>% + dplyr::mutate(category = dplyr::case_when( + is.null(comment_txt) ~ NA_character_, + is.na(comment_txt) ~ NA_character_, + comment_txt %in% c("NULL", "NA", "N/A") ~ NA_character_, + TRUE ~ category + )) + } else { + + data + } } diff --git a/app.R b/app.R index abf966f..e40688e 100644 --- a/app.R +++ b/app.R @@ -2,7 +2,7 @@ # To deploy, run: rsconnect::deployApp() # Or use the blue button on top of this file -Sys.setenv("R_CONFIG_ACTIVE" = "trust_a") +Sys.setenv("R_CONFIG_ACTIVE" = "trust_b") pkgload::load_all(export_all = FALSE, helpers = FALSE, diff --git a/man/tidy_all_trusts.Rd b/man/tidy_all_trusts.Rd index db745be..e95c68f 100644 --- a/man/tidy_all_trusts.Rd +++ b/man/tidy_all_trusts.Rd @@ -4,7 +4,7 @@ \alias{tidy_all_trusts} \title{Tidy patient experience data} \usage{ -tidy_all_trusts(data, conn, trust_id) +tidy_all_trusts(data, conn) } \arguments{ \item{data}{dataframe or SQL object, that you can make with get_px_exp()}