@@ -343,8 +343,7 @@ ui_g_scatterplot <- function(id, ...) {
343343 teal.widgets :: plot_with_settings_ui(id = ns(" scatter_plot" )),
344344 tags $ h1(tags $ strong(" Selected points:" ), class = " text-center font-150p" ),
345345 teal.widgets :: get_dt_rows(ns(" data_table" ), ns(" data_table_rows" )),
346- uiOutput(ns(" brush_filter" )),
347- DT :: dataTableOutput(ns(" data_table" ), width = " 100%" )
346+ ui_brush_filter(ns(" brush_filter" ))
348347 ),
349348 encoding = tags $ div(
350349 # ## Reporter
@@ -1002,78 +1001,16 @@ srv_g_scatterplot <- function(id,
10021001 click = TRUE
10031002 )
10041003
1005- output $ brush_filter <- renderUI({
1006- states <- get_filter_state(filter_panel_api )
1007- brushed_states <- Filter(
1008- function (state ) state $ id == " brush_filter" ,
1009- states
1010- )
1011- if (! is.null(pws $ brush())) {
1012- actionButton(session $ ns(" apply_brush_filter" ), " Apply filter" )
1013- } else if (length(brushed_states )) {
1014- actionButton(session $ ns(" remove_brush_filter" ), " Remove applied filter" )
1015- }
1016- })
1017-
1018- observeEvent(input $ remove_brush_filter , {
1019- remove_filter_state(
1020- filter_panel_api ,
1021- teal_slices(
1022- teal_slice(
1023- dataname = " ADSL" ,
1024- varname = " USUBJID" ,
1025- id = " brush_filter"
1026- )
1027- )
1028- )
1029- })
1030-
1031- observeEvent(input $ apply_brush_filter , {
1032- plot_brush <- pws $ brush()
1033- merged_data <- isolate(teal.code :: dev_suppress(output_q()[[" ANL" ]]))
1034- filter_call <- str2lang(sprintf(
1035- " merged_data <- dplyr::filter(merged_data, %1$s >= %2$s & %1$s <= %3$s & %4$s >= %5$s & %4$s <= %6$s)" ,
1036- plot_brush $ mapping $ x , plot_brush $ xmin , plot_brush $ xmax ,
1037- plot_brush $ mapping $ y , plot_brush $ ymin , plot_brush $ ymax
1038- ))
1039- eval(filter_call )
1040-
1041- slice <- teal_slices(teal_slice(
1042- dataname = " ADSL" ,
1043- varname = " USUBJID" ,
1044- selected = merged_data $ USUBJID ,
1045- id = " brush_filter"
1046- ))
1047- set_filter_state(filter_panel_api , slice )
1048- })
1049-
1050- output $ data_table <- DT :: renderDataTable({
1051- plot_brush <- pws $ brush()
1052-
1053- if (! is.null(plot_brush )) {
1054- validate(need(! input $ add_density , " Brushing feature is currently not supported when plot has marginal density" ))
1055- }
1056-
1057- merged_data <- isolate(teal.code :: dev_suppress(output_q()[[" ANL" ]]))
1058- brushed_df <- teal.widgets :: clean_brushedPoints(merged_data , plot_brush )
1059- numeric_cols <- names(brushed_df )[
1060- vapply(brushed_df , function (x ) is.numeric(x ) && ! is.integer(x ), FUN.VALUE = logical (1 ))
1061- ]
1062-
1063- if (length(numeric_cols ) > 0 ) {
1064- DT :: formatRound(
1065- DT :: datatable(brushed_df ,
1066- rownames = FALSE ,
1067- options = list (scrollX = TRUE , pageLength = input $ data_table_rows )
1068- ),
1069- numeric_cols ,
1070- table_dec
1071- )
1072- } else {
1073- DT :: datatable(brushed_df , rownames = FALSE , options = list (scrollX = TRUE , pageLength = input $ data_table_rows ))
1074- }
1075- })
1076-
1004+ # todo:
1005+ # validate(need(!input$add_density, "Brushing feature is currently not supported when plot has marginal density"))
1006+ srv_brush_filter(
1007+ " brush_filter" ,
1008+ brush = pws $ brush ,
1009+ data = output_q ,
1010+ filter_panel_api = filter_panel_api ,
1011+ selectors = selector_list ,
1012+ table_dec = table_dec
1013+ )
10771014
10781015 teal.widgets :: verbatim_popup_srv(
10791016 id = " rcode" ,
0 commit comments