Skip to content

Commit

Permalink
Bugfix/codebook export (#126)
Browse files Browse the repository at this point in the history
* Update export when code category map changes
  • Loading branch information
skvrnami committed Dec 29, 2023
1 parent 93ac991 commit 319f741
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: requal
Title: Shiny Application for Computer-Assisted Qualitative Data Analysis
Version: 1.1.0
Version: 1.1.0.9001
Authors@R:
c(
person(given = "Radim",
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# requal 1.0.1
# requal 1.1.0

- update UI
- add codebook export
- implement shinytest2 tests (see DEV-NOTES.md)

Expand Down
12 changes: 9 additions & 3 deletions R/mod_categories.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ mod_categories_server <- function(id, glob) {
)
})




# List existing codes in code boxes -------------------
output$uncategorized <- renderUI({
glob$codebook
Expand Down Expand Up @@ -213,6 +210,9 @@ mod_categories_server <- function(id, glob) {
user_id = glob$user$user_id,
edge = input$edges_category
)

glob$category_code_map <- read_category_edges(
glob$pool, glob$active_project)
} else {
warn_user("You don't have permissions for modifying codes and categories created by others.")
# TODO: delete code from category
Expand All @@ -225,6 +225,9 @@ mod_categories_server <- function(id, glob) {
user_id = glob$user$user_id,
edge = input$edges_category
)

glob$category_code_map <- read_category_edges(
glob$pool, glob$active_project)
}
})

Expand All @@ -236,6 +239,9 @@ mod_categories_server <- function(id, glob) {
user_id = glob$user$user_id,
edge = input$edges_category_delete
)

glob$category_code_map <- read_category_edges(
glob$pool, glob$active_project)
})

# return active categories details in glob$category ----
Expand Down
12 changes: 10 additions & 2 deletions R/mod_categories_utils_categories.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ render_categories <- function(id, pool,
}

# Read categories--------------------------------------------------------

read_db_categories <- function(pool, active_project, user) {
category_id <- category_description <- category_name <- NULL

Expand All @@ -131,6 +130,16 @@ read_db_categories <- function(pool, active_project, user) {
return(project_categories)
}

read_category_edges <- function(pool, active_project){
dplyr::tbl(pool, "categories_codes_map") %>%
dplyr::filter(.data$project_id == as.integer(.env$active_project)) %>%
dplyr::select(
category_id,
code_id
) %>%
dplyr::collect()
}

# List categories--------------------------------------------------------


Expand Down Expand Up @@ -253,7 +262,6 @@ add_category_code_record <- function(pool,
}

# delete edge record -----

delete_category_code_record <- function(pool,
active_project,
edge,
Expand Down
27 changes: 16 additions & 11 deletions R/mod_csv_handler.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ get_codebook_export_table <- function(glob){
category_name)) %>%
dplyr::select(-c(category_name, category_description))

dplyr::tbl(glob$pool, "categories_codes_map") %>%
categories_map <- dplyr::tbl(glob$pool, "categories_codes_map") %>%
dplyr::collect() %>%
dplyr::inner_join(categories, by = "category_id") %>%
dplyr::left_join(glob$codebook, by = "code_id") %>%
dplyr::inner_join(categories, by = "category_id")

dplyr::left_join(glob$codebook, categories_map, by = "code_id") %>%
dplyr::group_by(code_id, code_name, code_description) %>%
dplyr::summarise(categories = paste0(category_title, collapse = ", "))
}
Expand All @@ -56,15 +57,19 @@ mod_download_csv_server <- function(id, glob){
moduleServer(id, function(input, output, session){
ns <- session$ns

output$download_analysis <- handle_download(
paste0("requal_export-", format(Sys.time(), "%Y-%m-%d-%H%M%S"), ".csv"),
glob$segments_df
)
observeEvent(glob$segments_df, {
output$download_analysis <- handle_download(
paste0("requal_export-", format(Sys.time(), "%Y-%m-%d-%H%M%S"), ".csv"),
glob$segments_df
)
})

output$download_codebook <- handle_download(
paste0("requal_codebook_export-", format(Sys.time(), "%Y-%m-%d-%H%M%S"), ".csv"),
get_codebook_export_table(glob)
)
observeEvent(c(glob$codebook, glob$category, glob$category_code_map), {
output$download_codebook <- handle_download(
paste0("requal_codebook_export-", format(Sys.time(), "%Y-%m-%d-%H%M%S"), ".csv"),
get_codebook_export_table(glob)
)
})
})
}

Expand Down

0 comments on commit 319f741

Please sign in to comment.