shiny icon indicating copy to clipboard operation
shiny copied to clipboard

Should make interactive plot click information behave more consistently

Open wch opened this issue 5 years ago • 3 comments

Currently, when a plot is scaled in the browser:

  • It will re-send updated brush information (with updated pixelratio)
  • It will not re-send updated click/hover/dblclick information

When a plot is re-drawn on the server and sent to the client:

  • It will re-send updated brush information
  • click/hover/dblclick information will be set to NULL

We should make the behavior more consistent. Part of the problem is figuring out whether the click information should represent events, or states. We could make this customizable in click options.

A simple way to demonstrate both of these is with renderCachedPlot(). In the following app, it is possible to resize the window so that it is scaled in the browser, but if you cross certain size thresholds, the server will redraw the plot.

library(shiny)
library(ggplot2)

shinyApp(
  fluidPage(
    sidebarLayout(
      sidebarPanel(
        actionButton("redraw", "Redraw plot"),
        checkboxInput("ggplot2", "ggplot2")
      ),
      mainPanel(
        plotOutput("plot",
          click = "plot_click",
          brush = "plot_brush"
        ),
        verbatimTextOutput("click_info"),
        verbatimTextOutput("brush_info")
      )
    )
  ),
  function(input, output, session) {
    output$plot <- renderCachedPlot(
      {
        cat("renderCachedPlot user code\n")
        if (input$ggplot2) {
          ggplot(mtcars, aes(wt, mpg)) + geom_point()
        } else {
          plot(mpg~wt, data = mtcars)
        }
      },
      cacheKeyExpr = { list(input$ggplot2) }
    )
    
    output$click_info <- renderPrint({
      str(input$plot_click)
    })
    output$brush_info <- renderPrint({
      str(input$plot_brush)
    })
  }
)

wch avatar Aug 11 '18 00:08 wch

@wch Is this something we need for v1.2? (i.e. in the next week)

jcheng5 avatar Sep 14 '18 16:09 jcheng5

Removing from 1.2 milestone. Can be fixed at a later date

schloerke avatar Sep 17 '18 16:09 schloerke

Since I'm working on other brush-related fixes at https://github.com/dvg-p4/shiny I could try to work in some consistency here too. Any thoughts as to what the "correct" behavior should be?

dvg-p4 avatar Jul 01 '22 18:07 dvg-p4