Если аргумент source
графика установлен на XXX
(по умолчанию A
), тогда вы должны установить вход plotly_selected-XXX
на NULL
.Это можно сделать с помощью shinyjs
:
library(shiny)
library(plotly)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
actionButton("reset", "Reset"),
plotlyOutput("plot")
)
server <- function(input, output){
output[["plot"]] <- renderPlotly({
df <- data.frame(
x = c(1,2,1),
y = c(1,2,1)
)
df %>%
plot_ly(
x = ~x,
y = ~y,
source = "A",
type = 'scatter',
mode = 'markers',
marker = list(size = 20),
showlegend = FALSE
)
})
observeEvent(input[["reset"]], {
runjs("Shiny.setInputValue('plotly_selected-A', null);")
})
observe({ # just to test
print(event_data("plotly_selected", source = "A"))
})
}
shinyApp(ui, server)