Skip to content

Commit

Permalink
Merge pull request #93 from CDU-data-science-team/92-fix-empty
Browse files Browse the repository at this point in the history
92 fix empty
  • Loading branch information
ChrisBeeley authored Dec 10, 2021
2 parents d1ece49 + 66f917f commit 545ecd8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
30 changes: 15 additions & 15 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand All @@ -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")) %>%
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"){
Expand Down
26 changes: 18 additions & 8 deletions R/tidy_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion app.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion man/tidy_all_trusts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 545ecd8

Please sign in to comment.