I'm trying to visualize a lot of data on a 3D plot, and have been using click events to display additional data on the selected marker. It becomes very difficult to see which marker is selected without a color change.
There are several solutions using js event listener that don't work on scatter3D. This solution does successfully generate a point, but it skews the camera angles of my vis and doesn't scale with size like my markers do, so doesn't actually appear to replace them.
plotlyProxy and plotlyProxyInvoke do successfully change color and size of markers when a marker is clicked, but they change color and size of ALL markers. I do not know how to reference the specific marker point.
library(shiny)
library(ggplot2)
library(plotly)
ui <- navbarPage("Page",
page1 <- fluidPage(
titlePanel("Panel"),
plotlyOutput('plot'))
)
server <- function(input, output, session) {
output$plot <- renderPlotly({
p <- plot_ly()
p <- add_trace(p,
data = mtcars,
x = ~mpg,
y = ~cyl,
z = ~wt,
color = ~hp,
type = 'scatter3d',
mode = "markers")
})
I've left the click event data variable in, but it doesn't actually work when I try to use it anywhere in the plotlyProxyInvoke function.
observeEvent(event_data("plotly_click"), {
#clickpoint <- event_data("plotly_click")$pointNumber[1] + 1
plotlyProxy("plot", session) %>%
plotlyProxyInvoke("restyle", list(marker = list(opacity = 1, color = "red")))
})
}
shinyApp(ui = ui, server = server)
When I run this code and click once, all markers will change according to my event, rather than just the selected marker.