3
votes

I typically use print when I'm building shinyapps as a way to check to make sure what I think should happen is actually what is happening. However, I've run into a problem where print is no longer printing to the R console when I have an app running. Here's a simple example of what I've tried:

ui <- fluidPage(
  sliderInput("slider", "Slider Range",
          min = 0, max = 5000, value = c(11))
)

server <- function(input, output){
  print("Non-Reactive")  
  new <- reactive({
    print("Reactive")
    print(input$slider)
  })

}

shinyApp(ui, server)

Within the R console, I get: [1] "Non-Reactive" and that is it. No [1] "Reactive" or [1] 11 for my slider.

I know it used to work before, but I'm not sure what changed. If there's another easier way to check/debug code for shinyapps aside from print I'd love to know my other options too.

Note: My shinyapp package is version 0.13.0. My RStudio version is 0.99.491. R is currently 3.2.2.

1
an object is reactive if the code that builds it calls a widget value. - mtoto
In this case, the print(input$slider) is calling from a widget value, right? - puginablanket
Well, that did it. So what does observe() do to cause it to finally print stuff? Can you think of why it would've worked previously without observe but now doesn't? Thanks for the quick solution! - puginablanket
Ohh. So if I had print(input$slider) on any other type of shiny function (like renderPrint) it would have done it? Maybe I've somehow avoided using print() when verifying things before. - puginablanket

1 Answers

2
votes

As jenesaisquoi mentioned, I had to use observe(new()) later in my server code in order to observe changes in the reactive() function. I must just by dumb luck never used print() in a reactive() function when testing things.