3

I think I'm missing some basic aspect of ggvis + shiny.

Following the tutorials, plots are constructed in server.R using a series of %>% pipes, ending with bind_shiny, which associates the plot with an identifier that can be referred to in ui.R

What I don't get though is that the plot itself is not reactive in the way that code within renderTable(), renderText() or reactive() will be. So if I want to refer to an input parameter like input$x in defining the plot, it won't work, I'll get an error saying "Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)".

For example, if 'input' is the input parameter to the shinyServer function, I might have a plot that looks like:

dataframe %>% ggvis(~ aval, ~ bval) %>% layer_points %>% layer_paths(x = ~xv, y = ~ yv, data = data.frame(xv = c(0, 0), yv = c(0, input$maxValParam)))

where layeR_points is used to plot data in dataframe and layer_paths is being used to draw a vertical line up to the maxValParam value.

1 Answer 1

6

So this answer might be useful.

It looks like in order to reference your input$maxValParam inside a ggvis() function, the entire ggvis function needs to be wrapped in a reactive. blatantly ripping off the above answer, yours might look something like:

reactive({
  dataframe %>% 
      ggvis() #rest of plotting code %>% 
      add_axis("x", title = input$maxValParam)
}) %>% bind_shiny("plot")
Sign up to request clarification or add additional context in comments.

2 Comments

any idea why ggvis is implemented using bind_shiny() function while the shiny reactive plots have their own renderXXX() function? This works but it's kind of confusing that it's not consistent.
I have no idea... I think it has to do with ggvis being interactive as a standalone, so it probably needs different methods. Ggvis documentation might have a clue. Or just ask Hadley.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.