@@ -263,11 +263,11 @@ srv_variable_browser <- function(id,
263263 establish_updating_selection(datanames , input , plot_var , columns_names )
264264
265265 # validations
266- validation_checks <- validate_input(req(input ), req(plot_var ), req( data ) )
266+ validation_checks <- validate_input(req(input ), req(plot_var ), data )
267267
268268 # data_for_analysis is a list with two elements: a column from a dataset and the column label
269269 plotted_data <- reactive({
270- req(input , plot_var , data )
270+ req(input , plot_var , data() )
271271 validation_checks()
272272 get_plotted_data(input , plot_var , data )
273273 })
@@ -311,10 +311,10 @@ srv_variable_browser <- function(id,
311311 })
312312
313313 output $ ui_numeric_display <- renderUI({
314+ dataname <- req(input $ tabset_panel )
315+ varname <- req(plot_var $ variable )[[dataname ]]
316+ df <- req(data())[[dataname ]]
314317 validation_checks()
315- dataname <- input $ tabset_panel
316- varname <- plot_var $ variable [[dataname ]]
317- df <- data()[[dataname ]]
318318
319319 numeric_ui <- bslib :: page_fluid(
320320 bslib :: layout_columns(
@@ -377,9 +377,9 @@ srv_variable_browser <- function(id,
377377
378378 output $ ui_histogram_display <- renderUI({
379379 validation_checks()
380- dataname <- input $ tabset_panel
381- varname <- plot_var $ variable [[dataname ]]
382- df <- data()[[dataname ]]
380+ dataname <- req( input $ tabset_panel )
381+ varname <- req( plot_var $ variable ) [[dataname ]]
382+ df <- req( data() )[[dataname ]]
383383
384384 numeric_ui <- bslib :: input_switch(
385385 id = session $ ns(" remove_NA_hist" ),
@@ -445,11 +445,24 @@ srv_variable_browser <- function(id,
445445 }
446446 })
447447
448+ output $ variable_summary_table <- DT :: renderDataTable({
449+ var_summary_table(
450+ plotted_data()$ ANL [, 1 , drop = TRUE ],
451+ treat_numeric_as_factor(),
452+ input $ variable_summary_table_rows ,
453+ if (! is.null(input $ remove_outliers ) && input $ remove_outliers ) {
454+ req(input $ outlier_definition_slider )
455+ as.numeric(input $ outlier_definition_slider )
456+ } else {
457+ 0
458+ }
459+ )
460+ })
448461
449462 variable_plot_r <- reactive({
450463 req(plotted_data())
451- display_density <- `if`(is.null(input $ display_density ), FALSE , req( input $ display_density ) )
452- remove_outliers <- `if`(is.null(input $ remove_outliers ), FALSE , req( input $ remove_outliers ) )
464+ display_density <- `if`(is.null(input $ display_density ), FALSE , input $ display_density )
465+ remove_outliers <- `if`(is.null(input $ remove_outliers ), FALSE , input $ remove_outliers )
453466
454467 if (remove_outliers ) {
455468 req(input $ outlier_definition_slider )
@@ -459,7 +472,7 @@ srv_variable_browser <- function(id,
459472 }
460473
461474 plot_var_summary(
462- qenv = plotted_data(),
475+ qenv = req( plotted_data() ),
463476 # var = plotted_data()$data,
464477 # var_lab = plotted_data()$var_description,
465478 wrap_character = 15 ,
@@ -483,20 +496,6 @@ srv_variable_browser <- function(id,
483496 height = c(500 , 200 , 2000 )
484497 )
485498
486- output $ variable_summary_table <- DT :: renderDataTable({
487- var_summary_table(
488- plotted_data()$ ANL [, 1 , drop = TRUE ],
489- treat_numeric_as_factor(),
490- input $ variable_summary_table_rows ,
491- if (! is.null(input $ remove_outliers ) && input $ remove_outliers ) {
492- req(input $ outlier_definition_slider )
493- as.numeric(input $ outlier_definition_slider )
494- } else {
495- 0
496- }
497- )
498- })
499-
500499 set_chunk_dims(pws , variable_plot_r )
501500 })
502501}
@@ -735,10 +734,11 @@ plot_var_summary <- function(qenv,
735734 ))
736735 qenv <- within(qenv , {
737736 remove_outliers <- remove_outliers_from
738- ANL <- filter(ANL , remove_outliers(var_name ))
737+ ANL <- filter(ANL , remove_outliers(var_name , outlier_definition ))
739738 },
740739 remove_outliers_from = filter_outliers ,
741- var_name = as.name(var_name ))
740+ var_name = as.name(var_name ),
741+ outlier_definition = outlier_definition )
742742 }
743743
744744 # # histogram
@@ -760,7 +760,8 @@ plot_var_summary <- function(qenv,
760760 if (display_density ) {
761761 qenv_plot <- within(qenv_plot , {
762762 plot <- plot + ggplot2 :: geom_density(ggplot2 :: aes(y = ggplot2 :: after_stat(count * binwidth )))
763- })
763+ },
764+ binwidth = binwidth )
764765 }
765766 if (outlier_definition != 0 ) {
766767 qenv_plot <- within(qenv_plot , {
@@ -789,7 +790,6 @@ plot_var_summary <- function(qenv,
789790 ANL [[var ]] <- as.numeric(ANL [[var ]])
790791 attr(ANL [[var ]], " label" ) <- col_label
791792 plot <- ANL %> %
792- mutate(var_name = as.numeric(var_name )) %> %
793793 ggplot2 :: ggplot(ggplot2 :: aes(x = var_name , y = ggplot2 :: after_stat(count ))) +
794794 ggplot2 :: geom_histogram(binwidth = binwidth )
795795 },
0 commit comments