R在情节选择重置后删除标记的矩形 [英] R remove marked rectangle after plotly selection reset

查看:39
本文介绍了R在情节选择重置后删除标记的矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用@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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆