rstudio / crosstalk

Inter-htmlwidget communication for R (with and without Shiny)
http://rstudio.github.io/crosstalk
Other
290 stars 53 forks source link

crosstalk.FilterHandle doesn't return the same type consistently #140

Open daattali opened 1 year ago

daattali commented 1 year ago

When a filter_select() is used, the FilterHandle callback returns the keys as a string array. When a filter_slider() is used, a numeric array is returned.

Example:

library(shiny)

df <- data.frame(id = 1:5, num1 = 11:15, num2 = 21:25)
shared_df <- crosstalk::SharedData$new(df, key = ~id, group = 'test')

ui <- fluidPage(
  crosstalk::filter_select("num1", "num1", shared_df, ~num1),
  crosstalk::filter_slider("num2", "num2", shared_df, ~num2, step = 1),

  tags$script(HTML(
    'ctFil = new crosstalk.FilterHandle("test");
     ctFil.on("change", function(e) { console.log(e.value); });'
  ))
)

server <- function(input, output, session) {}

shinyApp(ui, server)

Make selections using either filter, and look at the javascript console.

https://www.loom.com/share/bb379b56dd2349e48b894895d15ba7c1