Interactivity in ggvis



i am new to R. Can anyone please help me fix this problem. Whenever I run this command i get this error and i am unable to resolve it.

mtcars %>%
  ggvis(~wt, ~mpg, size := input_slider(10, 1000)) %>%
  layer_points(fill := "red") %>%
  layer_points(stroke := "black", fill := NA)

Please tell the correct way to use input_slider function.


Hi, and welcome to!

Without knowing how your shiny app.R code is structured, it's a little difficult to give good guidance. Have you placed this inside a shiny app, or are you attempting to run just the code you've entered here?

To help you get the right help for your question, can you please turn it into a reprex (reproducible example)? This will ensure we're all looking at the same data and code. A guide for creating a reprex can be found here.

You may also find the "Shiny Apps" section of this page useful (though it seems a bit out of date, as it refers to ui.R and server.R instead of app.R).


Hi @swati! Welcome!

It looks like you didn't include the error message in your post, so I'm afraid it's a little hard to know what's going wrong here.

As an aside, this question seems to be about ggvis, not shiny — although ggvis is built on top of shiny technology, it's not quite the same thing. I adjusted the categories and tags to reflect that. If that's wrong and this code is actually inside a shiny app, please feel free to change them back! (you can do this by clicking the little pencil icon at the end of the post title). If you aren't running this code inside a shiny app, it might be a good idea to choose a different title to attract the right helpers to your problem.


This is the command which I am running.

mtcars %>% 
  ggvis(~wt, ~mpg, 
        size := input_slider(10, 100),
        opacity := input_slider(0, 1)
  ) %>% 

And this is the error message which I am getting:

Error in mtcars %>% ggvis(~wt, ~mpg, `:=`(size, input_slider(10, 100)),  : 
  could not find function "%>%"

Thanks alot for your help.


The error is resulting from R not knowing what to do with the pipe (%>%), which is provided by a number of different packages, including ggvis — so the fact that you are getting this error suggests that you didn't load ggvis before running the code. You load packages using library("packageName").

So in this case, try:


mtcars %>% 
  ggvis(~wt, ~mpg, 
        size := input_slider(10, 100),
        opacity := input_slider(0, 1)
  ) %>% 

You only need to load the library once per session, but you need to do it every time you start a new session. It's good practice to put your library() statements at the very top of your scripts, so that the necessary packages get loaded first thing and so that you can easily see which packages a script uses.


yeah it worked....thanks alot


If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it: