@@ -343,6 +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" )),
346347 DT :: dataTableOutput(ns(" data_table" ), width = " 100%" )
347348 ),
348349 encoding = tags $ div(
@@ -997,9 +998,55 @@ srv_g_scatterplot <- function(id,
997998 plot_r = plot_r ,
998999 height = plot_height ,
9991000 width = plot_width ,
1000- brushing = TRUE
1001+ brushing = TRUE ,
1002+ click = TRUE
10011003 )
10021004
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+
10031050 output $ data_table <- DT :: renderDataTable({
10041051 plot_brush <- pws $ brush()
10051052
@@ -1008,7 +1055,6 @@ srv_g_scatterplot <- function(id,
10081055 }
10091056
10101057 merged_data <- isolate(teal.code :: dev_suppress(output_q()[[" ANL" ]]))
1011-
10121058 brushed_df <- teal.widgets :: clean_brushedPoints(merged_data , plot_brush )
10131059 numeric_cols <- names(brushed_df )[
10141060 vapply(brushed_df , function (x ) is.numeric(x ) && ! is.integer(x ), FUN.VALUE = logical (1 ))
@@ -1028,6 +1074,7 @@ srv_g_scatterplot <- function(id,
10281074 }
10291075 })
10301076
1077+
10311078 teal.widgets :: verbatim_popup_srv(
10321079 id = " rcode" ,
10331080 verbatim_content = reactive(teal.code :: get_code(output_q())),
0 commit comments