【发布时间】:2017-08-17 04:52:33
【问题描述】:
我正在设计一个包含plotly 散点图的闪亮应用程序。我希望用户能够单击图表以使用event_data 函数记录事件,然后能够通过单击actionButton 清除该事件。一些示例代码如下所示:
library(shiny)
library(plotly)
ui <- fluidPage(
actionButton("clearEvent", label = "clear event"),
verbatimTextOutput("plotVal"),
plotlyOutput('plot1')
)
server <- function(input, output, session) {
output$plot1 <- renderPlotly({
d <- diamonds[sample(nrow(diamonds), 1000), ]
plot_ly(d, x = ~carat, y = ~price, color = ~carat,
size = ~carat, text = ~paste("Clarity: ", clarity))
})
output$plotVal <- renderPrint({
e <- event_data("plotly_click")
if (is.null(e)) {
NULL
} else {
e
}
})
observeEvent(input[["clearEvent"]], {
e <- NULL
})
}
shinyApp(ui = ui, server = server)
但是,这并没有像我预期的那样清除事件。查看event_data 的代码表明这可能是因为它存储在session 对象本身中。有什么想法可以覆盖它吗?
我遇到的唯一类似的事情是Clear plotly click event,但它非常hacky,似乎不适合我。
【问题讨论】: