For my project I need to extract the x and y coordinates of the “Box Select” which I use to select data within a shiny app (as I need to filter according to these values within a time frame). To be more precise - I need the actual coordinates only of the created box, not the x/y values of the selected IDs inside.
JS - Event Handlers <- I saw here that the event handler has these coordinates (x and y array) and you can see them in the console - but how do I store them dynamically within R?
Thanks already.
library(shiny)
library(plotly)
ui <- fluidPage(
plotlyOutput('myPlot'),
)
server <- function(input, output, session){
output$myPlot = renderPlotly({
plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Species) %>%
layout(dragmode = "select")
})
}
shinyApp(ui, server)
You can extract the data using the event_data call:
library(shiny)
library(plotly)
ui <- fluidPage(
plotlyOutput('myPlot'),
verbatimTextOutput("se")
)
server <- function(input, output, session){
output$myPlot = renderPlotly({
plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Species) %>%
layout(dragmode = "select")
})
output$se <- renderPrint({
d <- event_data("plotly_selected")
d
})
}
shinyApp(ui, server)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With