overload reactive

Hi,
I would like to overload/extend the reactive function. The idea is to put some standard information like time consumption, debugging output inside that new function that allows me to better track what is going on.
Right now I am reproducing for each reactive I am creating things like

start.time <- base::Sys.time()
if (is.null(variable)) {
    if (DEBUG) {
      cat(file = stderr(), "inputData: NULL\n")
    }
    return(NULL)
  }
...
  printTimeEnd(start.time, "inputData")
  exportTestValues(inputData = {list(assays(retVal$scEx)[["counts"]], rowData(retVal$scEx), colData(retVal$scEx)) })  

Here, only the ... part is really changing and I wanted to use a list of reactive dependencies to that function and a name to be substituted...

Thanks
B

Two options come to mind. In shiny v1.3.0, (just released), there is a new option of options(shiny.reactlog = TRUE). Run your app like normal, then hit cmd + F3 or ctrl + F3 to open the reactlog. This might help with what is going on. Please look into profvis for code profiling.


If you're looking for a console output of the current execution, look into using debugme.

Example:



ui <- fluidPage(
  titlePanel("Hello Shiny!"),
  sidebarLayout(
    sidebarPanel(
      sliderInput("obs", "Number of observations:", min = 1, max = 1000, value = 500)
    ),
    mainPanel(plotOutput("distPlot"))
  )
)

server <- function(input, output) {
  debugme::debug("app started", pkg = "myshinyapp")
  
  output$distPlot <- renderPlot({
    debugme::debug("plot render start", pkg = "myshinyapp")
    on.exit({
      debugme::debug("plot render end", pkg = "myshinyapp")
    })
    
    # generate an rnorm distribution and plot it
    dist <- rnorm(input$obs)
    hist(dist)
  })
  
}

# enable your application's debugging
Sys.setenv(DEBUGME = "myshinyapp")
shinyApp(ui, server)
❯❯ shinyApp(ui, server)

Listening on http://127.0.0.1:7623
myshinyapp app started +9784ms 
myshinyapp plot render start +14ms 
myshinyapp plot render end +28ms 
myshinyapp plot render start +1999ms 
myshinyapp plot render end +34ms 
myshinyapp plot render start +2994ms 
myshinyapp plot render end +32ms 
myshinyapp plot render start +4496ms 
myshinyapp plot render end +24ms 

There are longer exec times for the start, as it is how long I waited to hit the button to produce a new plot. (They may be ignored.)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.