0

I've defined variables for use with ggplot in a renderPlot output. However, for this ggplot, it uses various dataframes depending on the inputs (managed by an event handler). I'm trying to use the ggplot data to create a nearPoints output, to display the x and y variables. Yet variables defined don't carry across between outputs, and it throws a, "____ (variable) not found" error in the nearPoints output.

Any suggestions, without having to rewrite the code defining each variable for every usage of it in the differing outputs? (Hope this helps understand the issue - can't share much code as it contains sensitive data). Thanks!!

Sean
  • 57
  • 6
  • Welcome to SO! It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a minimal working example code and a snippet of your data or some fake data. It's not necessary to share any sensitive data. You could create some fake data to mimic your real data or use one of the built-in datasets like `iris`or `mtcars` or ... – stefan Oct 04 '22 at 04:38
  • I'll try and generalise the code @stefan, ```server <- function(input, output){ output$plot1 <- renderPlot({ # define the choices vegeframe <- switch(input$abc, "beans" = dataframe1%>%filter(veg == beans), "cabbage" = dataframe1%>%filter(veg == cabbage) if (input$abc == "beans"){ x_var = dataframe1$beans } else{ x_var = dataframe1$cabbage } ggplot(data = vegeframe, aes(x = veg))+ geom_hist(aes(y = ..density..)) output$info <- renderPrint({ nearPoints(vegeframe, input$plot_click, threshold = 10, maxpoints = 1, addDist = TRUE) })``` – Sean Oct 04 '22 at 06:03
  • That formatting looks dreadful, apologies :/ Still very new to SO – Sean Oct 04 '22 at 06:04

0 Answers0