Shiny node reactivity dependency tree

I started supporting the Rshiny package of ~ 3000 lines of code. I would like to get an overview of what is running what is in the server.R file.

Is there a random way to generate a reactivity trigger dependency diagram?

+3


source to share


3 answers


You may be interested in this: https://www.r-bloggers.com/announcing-shinytester-a-package-that-helps-you-build-shiny-apps/



It represents a library named shinyTester

with a function ShinyHierarchy()

. For an example from this article, see the figure below. enter image description here

+4


source


There is a brilliant "reactive log renderer" built into brilliant. He gradually ramps up a graph that shows how different reactive nodes depend on each other. Its output after running looks like this:

enter image description here

Instructions for using this tool can be found here: Reactive Document Visualizer



These are my notes on this tool:

  • It is included with a line options(shiny.reactlog = TRUE)

    inserted before the call to shinyApp
  • This results in a log entry of how the nodes activate each other.
  • The log renderer can then be enabled with Ctrl-F3

    (or Command-F3

    on Apple)
  • There is a node explorer that can be manually overridden. This can be tricky when many nodes are displayed so that the lines do not intersect with each other.
  • You can then navigate backward in the journal (basically, you navigate in time in the journal) using the arrow keys.
  • Reactive symbols are described here: Brilliant overview of reactivity
  • It provides a lot of activity that is invisible to the user and can be confusing.
  • This doesn't work very well on large Shiny applications - many aspects of this tool just don't scale.
+3


source


The reactive logarithmic renderer is a powerful tool, but unfortunately it doesn't scale well with larger applications, as @Mike Wise pointed out. Some time ago I read some interesting ideas for improving the debugging experience in rstudio / shiny # 1846 and rstudio / shiny # 1532 and started looking into ways to implement them.

After a bit of stumbling around ( summary ), I found that the best way to do this is to parse the raw reactive log and build a dependency graph from it.

Package at https://github.com/glin/reactlog . Two main functions:

Displaying the call stack that caused the invalidation

observe({
  reactlog::traceInvalidation()
  rx()
})

      

4: observe({
       reactlog::traceInvalidation()
       rx()
   })
3: rx [<text>#7]
2: val =>  num 10
1: observe(val(10))

      

and listing reactive dependencies in a tree structure

observe({
  reactlog::listDependencies()
  rxA() + rxB() + rxAB()
}, label = "obs")

      

obs*
+-- rxA*
| `-- valA*
+-- rxB
| `-- valB
`-- rxAB*
  +-- valA*
  `-- valB

      

The tree view can be especially useful for checking if multiple dependencies have been invalidated (asterisks indicate invalidation or change).

+2


source







All Articles