crosstalk: selection interaction is wrong, it filters rows instead of selecting/highlighting
The {crosstalk} package provides functionality to link shiny widgets in two ways: selection and filtering. DT implements filtering correctly, and when rows in a DT table are selected then it correctly sends the selection signal. However, when rows are selected externally, DT does not correctly show the selection - it filters for these rows instead of highlighting them.
In the example below, if you use the filters, then both the plot and the table will show filtered data. This is correct. If you select rows in the table, then the corresponding data points will highlight in the plot. This is also correct. But if you highlight points in the plot, then the table will filter out the other data instead of highlighting the selected data.
library(shiny)
df <- crosstalk::SharedData$new(cars)
ui <- fluidPage(
crosstalk::filter_slider("speed", NULL, df, "speed"),
d3scatter::d3scatterOutput("plot"),
DT::DTOutput("table")
)
server <- function(input, output, session) {
output$plot <- d3scatter::renderD3scatter({
d3scatter::d3scatter(df, ~speed, ~dist)
})
output$table <- DT::renderDT(server = FALSE, {
DT::datatable(df)
})
}
shinyApp(ui, server)