I have the shiny app below in which I use crosstalk
package to create interaction between the chart and the table. I would like to ask if it is possible to select more than one bars at the same time in order to bring back the table to its initial form and also how can you unselect a bar without having to click on another one?
library(shiny)
library(ggplot2)
library(plotly)
library(DT)
library(crosstalk)
ui <- fluidPage(
plotlyOutput("plt"),
DT::dataTableOutput("dt")
)
server <- function(input, output) {
df <- data.frame(dose=c("D0.5", "D1", "D2"),
len=c(4.2, 10, 29.5))
df2 <- data.frame(dose=c("D0.5", "D1", "D2"),
siz=c(2, 10, 2.5))
shared_df <- SharedData$new(df, key = ~dose, group = "group")
shared_df2 <- SharedData$new(df2, key = ~dose, group = "group")
output$plt<-renderPlotly({
# Basic barplot
p <- ggplot(data=shared_df, aes(x=dose, y=len)) +
geom_bar(stat="identity")
ggplotly(p)
})
output$dt<-DT::renderDataTable({
shared_df2
}, server = FALSE)
}
shinyApp(ui, server)