Skip to content

Commit 4321350

Browse files
committed
data_table as a brushing table
1 parent 32ee42f commit 4321350

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

R/tm_data_table.R

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,16 @@ ui_page_data_table <- function(id,
181181
# Server page module
182182
srv_page_data_table <- function(id,
183183
data,
184-
datasets_selected,
185-
variables_selected,
186-
dt_args,
187-
dt_options,
188-
server_rendering,
184+
variables_selected = list(),
185+
datasets_selected = character(0),
186+
dt_args = list(),
187+
dt_options = list(
188+
searching = FALSE,
189+
pageLength = 30,
190+
lengthMenu = c(5, 15, 30, 100),
191+
scrollX = TRUE
192+
),
193+
server_rendering = FALSE,
189194
filter_panel_api) {
190195
checkmate::assert_class(data, "reactive")
191196
checkmate::assert_class(isolate(data()), "teal_data")

R/tm_p_swimlane2.r

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ ui_p_swimlane2 <- function(id) {
1616
ns <- NS(id)
1717
shiny::tagList(
1818
plotly::plotlyOutput(ns("plot")),
19-
verbatimTextOutput(ns("selecting")),
20-
shinyjs::hidden(tableOutput(ns("table")))
19+
ui_page_data_table(ns("brush_tables"))
2120
)
2221
}
2322

@@ -30,17 +29,44 @@ srv_p_swimlane2 <- function(id,
3029
plotly_q <- reactive({
3130
plotly_call <- .make_plotly_call(specs = plotly_specs)
3231
code <- substitute(
33-
p <- plotly_call %>% plotly::event_register("plotly_selecting"),
32+
p <- plotly_call,
3433
list(plotly_call = plotly_call)
3534
)
3635
eval_code(data(), code = code)
3736
})
3837

39-
output$plot <- plotly::renderPlotly(plotly_q()$p)
38+
output$plot <- plotly::renderPlotly(plotly::event_register(plotly_q()$p, "plotly_selected"))
4039

41-
output$selecting <- renderPrint({
42-
d <- plotly::event_data("plotly_selecting")
43-
if (is.null(d)) "Brush points appear here (double-click to clear)" else d
40+
41+
brush_filter_call <- reactive({
42+
d <- plotly::event_data("plotly_selected")
43+
req(d)
44+
calls <- lapply(plotly_specs, function(spec) {
45+
substitute(
46+
dataname <- dplyr::filter(dataname, var_x %in% levels_x, var_y %in% levels_y),
47+
list(
48+
dataname = spec$data,
49+
var_x = str2lang(all.vars(spec$x)),
50+
var_y = str2lang(all.vars(spec$y)),
51+
levels_x = d$x,
52+
levels_y = d$y
53+
)
54+
)
55+
})
56+
unique(calls)
57+
})
58+
59+
brush_filtered_data <- reactive({
60+
if (is.null(brush_filter_call())) {
61+
shinyjs::hide("brush_tables")
62+
} else {
63+
shinyjs::hide("show_tables")
64+
eval_code(plotly_q(), as.expression(brush_filter_call()))
65+
}
66+
})
67+
68+
observeEvent(brush_filtered_data(), once = TRUE, {
69+
srv_page_data_table("brush_tables", data = brush_filtered_data, filter_panel_api = filter_panel_api)
4470
})
4571
})
4672
}

0 commit comments

Comments
 (0)