@@ -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