Skip to content

Commit 947f151

Browse files
committed
encapsulate brushing functionality
1 parent d348719 commit 947f151

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

R/module_brush_filter.R

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
ui_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,

R/tm_g_scatterplot.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,6 @@ ui_g_scatterplot <- function(id, ...) {
341341
teal.widgets::standard_layout(
342342
output = teal.widgets::white_small_well(
343343
teal.widgets::plot_with_settings_ui(id = ns("scatter_plot")),
344-
tags$h1(tags$strong("Selected points:"), class = "text-center font-150p"),
345-
teal.widgets::get_dt_rows(ns("data_table"), ns("data_table_rows")),
346344
ui_brush_filter(ns("brush_filter"))
347345
),
348346
encoding = tags$div(

0 commit comments

Comments
 (0)