R在情节选择重置后删除标记的矩形 [英] R remove marked rectangle after plotly selection reset
问题描述
我使用@shosaco
它适用于重置数据但不重置标记的矩形:
你知道如何去掉那个矩形吗?
回答有点晚,但因为我刚刚面临同样的问题,所以我想我会在这里发布我的解决方案.您可以使用以下命令重置选择:
Plotly.restyle(plot, {selectedpoints: [null]});
将其添加到 extendShinyjs
调用将取消选择点并删除矩形,因此如下所示:
extendShinyjs(text = "shinyjs.resetClick = function() {Shiny.onInputChange('.clientValue-plotly_selected-A', 'null');Plotly.restyle('plot', {selectedpoints: [null]});}"),
I use @shosaco solution from here to reset selection in plotly:
library(shiny)
library(plotly)
library(shinyjs)
library(V8)
ui <- shinyUI(
fluidPage(
useShinyjs(),
extendShinyjs(text = "shinyjs.resetClick = function() { Shiny.onInputChange('.clientValue-plotly_selected-A', 'null'); }"),
actionButton("reset", "Reset plotly click value"),
plotlyOutput("plot"),
verbatimTextOutput("clickevent")
)
)
server <- shinyServer(function(input, output) {
output$plot <- renderPlotly({
plot_ly(mtcars, x=~cyl, y=~mpg)
})
output$clickevent <- renderPrint({
event_data("plotly_selected")
})
observeEvent(input$reset, {
js$resetClick()
})
})
shinyApp(ui, server)
and it works with resetting data but does not reset marked rectangle:
Do you have any ideas how to get rid of that rectangle?
A bit late to answer, but as I was facing the same problem just now, I thought I'd post my solution here. You can reset the selection with:
Plotly.restyle(plot, {selectedpoints: [null]});
Adding that to the extendShinyjs
call will deselect the points and remove the rectangle, so something like this:
extendShinyjs(
text = "shinyjs.resetClick = function() {
Shiny.onInputChange('.clientValue-plotly_selected-A', 'null');
Plotly.restyle('plot', {selectedpoints: [null]});
}"
),
这篇关于R在情节选择重置后删除标记的矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!