11ui_brush_filter <- function (id ) {
22 ns <- NS(id )
33 div(
4- uiOutput(ns(" brush_filter" )),
4+ tags $ h1(id = ns(" title" ), tags $ strong(" Selected points:" ), class = " text-center font-150p" ),
5+ teal.widgets :: get_dt_rows(ns(" data_table" ), ns(" data_table_rows" )),
6+ div(
7+ actionButton(ns(" apply_brush_filter" ), " Apply filter" ),
8+ actionButton(ns(" remove_brush_filter" ), " Remove applied filter" )
9+ ),
510 DT :: dataTableOutput(ns(" data_table" ), width = " 100%" )
611 )
712}
@@ -10,19 +15,36 @@ srv_brush_filter <- function(id, brush, data, filter_panel_api, selectors, table
1015 moduleServer(id , function (input , output , session ) {
1116 selector_list <- isolate(selectors())
1217
13- output $ brush_filter <- renderUI({
14- states <- get_filter_state(filter_panel_api )
18+ observeEvent(brush(), ignoreNULL = FALSE , {
19+ if (is.null(brush())) {
20+ shinyjs :: hide(" title" )
21+ shinyjs :: hide(" apply_brush_filter" )
22+ shinyjs :: hide(" data_table" )
23+ } else {
24+ shinyjs :: show(" title" )
25+ shinyjs :: show(" apply_brush_filter" )
26+ shinyjs :: show(" data_table" )
27+ }
28+ })
29+
30+ states_list <- reactive({
31+ as.list(get_filter_state(filter_panel_api ))
32+ })
33+
34+ observeEvent(states_list(), {
1535 brushed_states <- Filter(
1636 function (state ) state $ id == " brush_filter" ,
17- states
37+ states_list()
1838 )
19- if (! is.null(brush() )) {
20- actionButton( session $ ns( " apply_brush_filter " ), " Apply filter " )
21- } else if (length( brushed_states )) {
22- actionButton( session $ ns( " remove_brush_filter" ), " Remove applied filter " )
39+ if (length( brushed_states )) {
40+ shinyjs :: show( " remove_brush_filter " )
41+ } else {
42+ shinyjs :: hide( " remove_brush_filter" )
2343 }
2444 })
2545
46+
47+
2648 observeEvent(input $ remove_brush_filter , {
2749 remove_filter_state(
2850 filter_panel_api ,
0 commit comments