I try to setup an Rmd to get rendered in html (thus no shiny is allowed) .
I use ggiraph
and crosstalk
packages to create interactive plots.
I need to show the filtered table when a point on a plot is selected (similar to plotly
).
I found a relevant example here, but it requires shiny: run_girafe_example("DT")
server.R
library(ggplot2)
library(ggiraph)
shinyServer(function(input, output, session) {
output$plot_ <- renderGirafe({
data <- mtcars
data$label <- gsub(pattern = "'", " ", row.names(data) )
data$onclick <- paste0("set_search_val("", data$label, "");")
p <- ggplot(aes(x=wt, y=mpg,
tooltip = label,
data_id = label, onclick = onclick ),data=data) +
geom_point_interactive(size = 3) + theme_minimal()
girafe(code = print(p),
options = list(
opts_hover(css = "fill:red;cursor:pointer;"),
opts_selection(type = "single", css = "fill:red;")
)
)
})
output$dt_ <- DT::renderDataTable({
mtcars
})
})
ui.R
library(ggiraph)
library(htmltools)
shinyUI(fluidPage(
fluidRow(
column(width=12,
includeScript(path = "set_search_val.js"),
h4("click a point, the data table will be filtered...")
)
),
fluidRow(
column(width=6,
girafeOutput("plot_")
),
column(width=6,
DT::dataTableOutput("dt_")
)
)
))
Can it be adapted (with js??) to my case?
Thank you!