Skip to content

Commit

Permalink
239 utilize logger::log_shiny_input_change (#750)
Browse files Browse the repository at this point in the history
Close #239 

The example loading for `tm_a_pca` on a startup shows how the input
change logging is made.

We are connected to package namespace (`namespace =
"teal.modules.general"`)
that is created on a startup with
`teal.logger::register_logger(namespace = "teal.modules.general")`

This function needs to be called in the server function, so there is no
way this can be run during the package startup.

<img width="931" alt="image"
src="https://github.com/insightsengineering/teal.modules.general/assets/133694481/e9480872-4fd0-4c97-8b59-fdeba8fd41a2">

**Note:** Needed to bring `logger` to Imports.

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
m7pr and github-actions[bot] authored May 16, 2024
1 parent b7ace10 commit 18f8629
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 4 deletions.
7 changes: 3 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Imports:
DT (>= 0.13),
forcats (>= 1.0.0),
grid,
logger (>= 0.3.0),
scales,
shinyjs,
shinyTree (>= 0.2.8),
Expand Down Expand Up @@ -65,7 +66,6 @@ Suggests:
jsonlite,
knitr (>= 1.42),
lattice (>= 0.18-4),
logger (>= 0.2.0),
MASS,
nestcolor (>= 0.1.0),
pkgload,
Expand All @@ -81,7 +81,7 @@ VignetteBuilder:
Config/Needs/verdepcheck: haleyjeppson/ggmosaic, tidyverse/ggplot2,
rstudio/shiny, insightsengineering/teal,
insightsengineering/teal.transform, mllg/checkmate, tidyverse/dplyr,
rstudio/DT, tidyverse/forcats, r-lib/scales, daattali/shinyjs,
rstudio/DT, tidyverse/forcats, daroczig/logger, r-lib/scales, daattali/shinyjs,
shinyTree/shinyTree, rstudio/shinyvalidate, dreamRs/shinyWidgets,
tidyverse/stringr, insightsengineering/teal.code,
insightsengineering/teal.data, insightsengineering/teal.logger,
Expand All @@ -90,8 +90,7 @@ Config/Needs/verdepcheck: haleyjeppson/ggmosaic, tidyverse/ggplot2,
tidymodels/broom, daattali/colourpicker, daattali/ggExtra,
aphalo/ggpmisc, aphalo/ggpp, slowkow/ggrepel, baddstats/goftest,
gridExtra, ramnathv/htmlwidgets, jeroen/jsonlite, yihui/knitr,
deepayan/lattice, daroczig/logger, MASS,
insightsengineering/nestcolor, r-lib/rlang,
deepayan/lattice, MASS, insightsengineering/nestcolor, r-lib/rlang,
insightsengineering/rtables, tidyverse/rvest, sparkline,
rstudio/shinytest2, insightsengineering/teal.data, r-lib/testthat,
r-lib/withr
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

* Removed `Show Warnings` modals from modules.

### Enhancements
* Added `logger` functionality for logging changes in shiny inputs in all modules. `logger` was added to Imports.

# teal.modules.general 0.3.0

### Enhancements
Expand Down
2 changes: 2 additions & 0 deletions R/tm_a_pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")
moduleServer(id, function(input, output, session) {
if (shiny::isRunning()) logger::log_shiny_input_changes(input, namespace = "teal.modules.general")

response <- dat

for (i in seq_along(response)) {
Expand Down
2 changes: 2 additions & 0 deletions R/tm_a_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ srv_a_regression <- function(id,
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")
moduleServer(id, function(input, output, session) {
if (shiny::isRunning()) logger::log_shiny_input_changes(input, namespace = "teal.modules.general")

ns <- session$ns

rule_rvr1 <- function(value) {
Expand Down
2 changes: 2 additions & 0 deletions R/tm_data_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ srv_page_data_table <- function(id,
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")
moduleServer(id, function(input, output, session) {
if (shiny::isRunning()) logger::log_shiny_input_changes(input, namespace = "teal.modules.general")

if_filtered <- reactive(as.logical(input$if_filtered))
if_distinct <- reactive(as.logical(input$if_distinct))

Expand Down
2 changes: 2 additions & 0 deletions R/tm_file_viewer.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ ui_viewer <- function(id, ...) {
# Server function for the file viewer module
srv_viewer <- function(id, input_path) {
moduleServer(id, function(input, output, session) {
if (shiny::isRunning()) logger::log_shiny_input_changes(input, namespace = "teal.modules.general")

temp_dir <- tempfile()
if (!dir.exists(temp_dir)) {
dir.create(temp_dir, recursive = TRUE)
Expand Down
2 changes: 2 additions & 0 deletions R/tm_front_page.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ srv_front_page <- function(id, data, tables, show_metadata) {
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")
moduleServer(id, function(input, output, session) {
if (shiny::isRunning()) logger::log_shiny_input_changes(input, namespace = "teal.modules.general")

ns <- session$ns

setBookmarkExclude("metadata_button")
Expand Down
2 changes: 2 additions & 0 deletions R/tm_g_association.R
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ srv_tm_g_association <- function(id,
checkmate::assert_class(isolate(data()), "teal_data")

moduleServer(id, function(input, output, session) {
if (shiny::isRunning()) logger::log_shiny_input_changes(input, namespace = "teal.modules.general")

selector_list <- teal.transform::data_extract_multiple_srv(
data_extract = list(ref = ref, vars = vars),
datasets = data,
Expand Down
2 changes: 2 additions & 0 deletions R/tm_g_bivariate.R
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ srv_g_bivariate <- function(id,
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")
moduleServer(id, function(input, output, session) {
if (shiny::isRunning()) logger::log_shiny_input_changes(input, namespace = "teal.modules.general")

ns <- session$ns

data_extract <- list(
Expand Down
2 changes: 2 additions & 0 deletions R/tm_g_distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ srv_distribution <- function(id,
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")
moduleServer(id, function(input, output, session) {
if (shiny::isRunning()) logger::log_shiny_input_changes(input, namespace = "teal.modules.general")

setBookmarkExclude("params_reset")

ns <- session$ns
Expand Down
2 changes: 2 additions & 0 deletions R/tm_g_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ srv_g_response <- function(id,
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")
moduleServer(id, function(input, output, session) {
if (shiny::isRunning()) logger::log_shiny_input_changes(input, namespace = "teal.modules.general")

data_extract <- list(response = response, x = x, row_facet = row_facet, col_facet = col_facet)

rule_diff <- function(other) {
Expand Down
2 changes: 2 additions & 0 deletions R/tm_g_scatterplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ srv_g_scatterplot <- function(id,
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")
moduleServer(id, function(input, output, session) {
if (shiny::isRunning()) logger::log_shiny_input_changes(input, namespace = "teal.modules.general")

data_extract <- list(
x = x,
y = y,
Expand Down
2 changes: 2 additions & 0 deletions R/tm_g_scatterplotmatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")
moduleServer(id, function(input, output, session) {
if (shiny::isRunning()) logger::log_shiny_input_changes(input, namespace = "teal.modules.general")

selector_list <- teal.transform::data_extract_multiple_srv(
data_extract = list(variables = variables),
datasets = data,
Expand Down
2 changes: 2 additions & 0 deletions R/tm_missing_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ srv_page_missing_data <- function(id, data, reporter, filter_panel_api, parent_d
with_reporter <- !missing(reporter) && inherits(reporter, "Reporter")
with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI")
moduleServer(id, function(input, output, session) {
if (shiny::isRunning()) logger::log_shiny_input_changes(input, namespace = "teal.modules.general")

datanames <- isolate(teal.data::datanames(data()))
datanames <- Filter(function(name) {
is.data.frame(isolate(data())[[name]])
Expand Down
2 changes: 2 additions & 0 deletions R/tm_outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var,
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")
moduleServer(id, function(input, output, session) {
if (shiny::isRunning()) logger::log_shiny_input_changes(input, namespace = "teal.modules.general")

ns <- session$ns

vars <- list(outlier_var = outlier_var, categorical_var = categorical_var)
Expand Down
2 changes: 2 additions & 0 deletions R/tm_t_crosstable.R
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ srv_t_crosstable <- function(id, data, reporter, filter_panel_api, label, x, y,
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")
moduleServer(id, function(input, output, session) {
if (shiny::isRunning()) logger::log_shiny_input_changes(input, namespace = "teal.modules.general")

selector_list <- teal.transform::data_extract_multiple_srv(
data_extract = list(x = x, y = y),
datasets = data,
Expand Down
2 changes: 2 additions & 0 deletions R/tm_variable_browser.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ srv_variable_browser <- function(id,
checkmate::assert_class(data, "reactive")
checkmate::assert_class(isolate(data()), "teal_data")
moduleServer(id, function(input, output, session) {
if (shiny::isRunning()) logger::log_shiny_input_changes(input, namespace = "teal.modules.general")

# if there are < this number of unique records then a numeric
# variable can be treated as a factor and all factors with < this groups
# have their values plotted
Expand Down

0 comments on commit 18f8629

Please sign in to comment.