@@ -154,7 +154,9 @@ ui_g_spiderplot <- function(id, height) {
154154 selectInput(ns(" filter_event_var" ), label = " Event variable:" , choices = NULL , selected = NULL , multiple = FALSE ),
155155 selectInput(ns(" filter_event_var_level" ), label = " Select an event:" , choices = NULL , selected = NULL , multiple = FALSE ),
156156 colour_picker_ui(ns(" colors" )),
157- sliderInput(ns(" plot_height" ), " Plot Height (px)" , height [2 ], height [3 ], height [1 ])
157+ sliderInput(ns(" plot_height" ), " Plot Height (px)" , height [2 ], height [3 ], height [1 ]),
158+ selectInput(ns(" subjects" ), " Subjects" , choices = NULL , selected = NULL , multiple = TRUE ),
159+ actionButton(ns(" subject_tooltips" ), " Show Subject Tooltips" )
158160 ),
159161 tags $ div(
160162 bslib :: card(
@@ -269,13 +271,54 @@ srv_g_spiderplot <- function(id,
269271 output $ plot <- output $ plot <- plotly :: renderPlotly(plotly :: event_register(
270272 {
271273 plotly_q()$ p | >
274+ set_plot_data(session $ ns(" plot_data" )) | >
272275 setup_trigger_tooltips(session $ ns )
273276 },
274277 " plotly_selected"
275278 ))
276279
280+ observeEvent(data(), {
281+ if (class(subject_var ) == " choices_selected" ) {
282+ subject_col <- subject_var $ selected
283+ } else {
284+ subject_col <- subject_var
285+ }
286+ updateSelectInput(
287+ inputId = " subjects" ,
288+ choices = data()[[plot_dataname ]][[subject_col ]]
289+ )
290+ })
291+
292+ plotly_data <- reactive({
293+ data.frame (
294+ x = unlist(input $ plot_data $ x ),
295+ y = unlist(input $ plot_data $ y ),
296+ customdata = unlist(input $ plot_data $ customdata ),
297+ curve = unlist(input $ plot_data $ curveNumber ),
298+ index = unlist(input $ plot_data $ pointNumber )
299+ )
300+ })
301+
277302 plotly_selected <- reactive(plotly :: event_data(" plotly_selected" , source = " spiderplot" ))
278303
304+ observeEvent(input $ subject_tooltips , {
305+ hovervalues <- data()[[plot_dataname ]] | >
306+ dplyr :: mutate(customdata = dplyr :: row_number()) | >
307+ dplyr :: filter(!! rlang :: sym(input $ subject_var ) %in% input $ subjects ) | >
308+ dplyr :: pull(customdata )
309+
310+ hovertips <- plotly_data() | >
311+ dplyr :: filter(customdata %in% hovervalues )
312+
313+ session $ sendCustomMessage(
314+ " triggerTooltips" ,
315+ list (
316+ plotID = session $ ns(" plot" ),
317+ tooltipPoints = jsonlite :: toJSON(hovertips )
318+ )
319+ )
320+ })
321+
279322 tables_selected_q <- .plotly_selected_filter_children(
280323 data = plotly_q ,
281324 plot_dataname = plot_dataname ,
@@ -302,6 +345,8 @@ spiderplotly <- function(
302345 subject_var_label <- .get_column_label(data , subject_var )
303346 time_var_label <- .get_column_label(data , time_var )
304347 value_var_label <- .get_column_label(data , value_var )
348+ data <- data | >
349+ dplyr :: mutate(customdata = dplyr :: row_number())
305350
306351 if (is.null(size_var )) {
307352 size <- point_size
@@ -340,15 +385,17 @@ spiderplotly <- function(
340385 x = ~ x ,
341386 y = ~ y ,
342387 xend = stats :: as.formula(sprintf(" ~%s" , time_var )),
343- yend = stats :: as.formula(sprintf(" ~%s" , value_var ))
388+ yend = stats :: as.formula(sprintf(" ~%s" , value_var )),
389+ customdata = NULL
344390 ) %> %
345391 plotly :: add_markers(
346392 x = stats :: as.formula(sprintf(" ~%s" , time_var )),
347393 y = stats :: as.formula(sprintf(" ~%s" , value_var )),
348394 symbol = stats :: as.formula(sprintf(" ~%s" , color_var )),
349395 size = size ,
350396 text = ~ tooltip ,
351- hoverinfo = " text"
397+ hoverinfo = " text" ,
398+ customdata = ~ customdata
352399 ) %> %
353400 plotly :: layout(
354401 xaxis = list (title = time_var_label ),
0 commit comments