Shiny's reactive expressions propagate changes where they need to go. We can suppress some of this behavior with isolate , but can we suppress propagated changes based on our own logical expression?
The example I give is a simple scatter chart, and we draw a crosshair with abline where the user clicks. Unfortunately, Shiny believes that the result is a new plot, and our click value is reset to NULL ... which, in turn, is considered an update for the value that will be distributed as usual. The plot is redrawn, and NULL is passed to both abline arguments.
My hack (commented below) is to put a condition in a call to renderPlot , which updates some non-reactive variables to build coordinates only when click values ββare not NULL . This is great for trivial graphs, but in fact it leads to the fact that the graph is drawn twice.
What is the best way to do this? Is it right?
Server file:
library(shiny) shinyServer(function (input, output) { xclick <- yclick <- NULL output$plot <- renderPlot({
UI file:
library(shiny) shinyUI( basicPage( plotOutput("plot", click = "click", height = "400px", width = "400px") ) )
source share