2

I am currently developing a complex (multiple pages of nested navs/tabs) web application using R's Shiny package.

I am currently experiencing an issue where sometimes accessing the values of these sliders from R via input$ returns NULL for no apparent reason. When this happens, the various outputs dependent on these sliders cannot be produced due to errors.

This problem goes away if the user forces the application to recalculate by changing an input.

The error occurs primarily at startup, though on occasion it will occur in the middle of a session as the user plays with the inputs.

I am currently working on a clean example to reproduce this, but if anyone has experienced this before or has any ideas I would certainly appreciate the help.

jrdnmdhl
  • 1,935
  • 18
  • 26

2 Answers2

1

As I just answered in a different question, try using observeEvent maybe? observeEvent fires the given expression when a reactive value changes BUT it ignores NULL values by default.

https://stackoverflow.com/a/30514860/3943160

Community
  • 1
  • 1
DeanAttali
  • 25,268
  • 10
  • 92
  • 118
  • It is useful to know that observeEvent ignores NULL values. How would I use this though given that observeEvent doesn't return anything? Does the same apply to eventReactive? – jrdnmdhl May 28 '15 at 19:47
  • I would think eventReactive is similar. The documentation for both functions is merged together so it's probably the same – DeanAttali May 28 '15 at 20:17
1

On the shiny google group, I was informed that this is expected behavior. The inputs take time to load and you must define what inputs are required to be non-null to produce each given output.

The solution here was to use the following in the relevant outputs:

shiny::validate(need(input$myinput, message=FALSE))

It is important to call validate this way as this name is used by other packages. I spent a long time trying to use validate and getting errors because it was calling the wrong validate function from a different package.

jrdnmdhl
  • 1,935
  • 18
  • 26