-
Notifications
You must be signed in to change notification settings - Fork 635
Open
Description
Hi - I'm trying to add/change traces in a graph with subplots. Below the example code.
It looks like each subplot becomes one trace (based on playing with the restyle section), but it is unclear to me how to add/remove traces. I changed the addTraces number at the end to 0-3 but it always adds it to the first subplot.
Any help would be appreciated.
data <- tibble(runmonth=c(1,1,1,1,4,4,4,4),variable=c('a','a','b','b','a','a','b','b'),x=c(1:8),y=c(8:1),keyname=paste0('k',c(1:8)))
p <- data %>% group_by(runmonth,variable) %>%
do(
p = highlight_key(., ~keyname,group='scattergroup') %>%
plot_ly(showlegend = FALSE) %>%
add_markers(
x = ~x, y = ~y
)
) %>%
subplot(
nrows = 2, margin = 0.01,
shareY = TRUE, shareX = TRUE, titleY = FALSE
) %>% toWebGL() %>%
highlight(
on = "plotly_selected",
off = c('plotly_relayout')
)
ui <- function(id) {
div(
actionButton('go','go'),
plotlyOutput("scattergr")
)
}
server <- function(input,output,session) {
output$scattergr <- renderPlotly({p})
observeEvent(input$go,{
plotlyProxy("scattergr", session) %>%
plotlyProxyInvoke(
"restyle",
list(
'marker.symbol' = list(c(rep('triangle-up',1),'circle'))
),
list(0,1,2,3)
) %>%
plotlyProxyInvoke(
"addTraces",
list(
x = c(50,60),
y = c(50,60),
mode = "scatter"
),1
) %>%
plotlyProxyInvoke(
"moveTraces",
-1,0
)
})
}
runApp(shinyApp(ui, server))
msummersgill and barrettk
Metadata
Metadata
Assignees
Labels
No labels