0

I am trying to plot multiple sets of points on a plot in an R Shiny app, using renderPlot. I've tried using the points function into a for loop which didn't work. I then tried with lapply. Here is what I currently have in the server file:

output$session_plot_Q <- renderPlot({
      
      plot(sectors[which(sectors$Minisector == 0),]$X, sectors[which(sectors$Minisector == 0),]$Y)
      lapply(1:25, function(x) {
        points(sectors[which(sectors$Minisector == x),]$X, sectors[which(sectors$Minisector == x),]$Y)
      })
      
    })

I am getting an output of only the set of points contained in the "plot" function, the first set of point to plot. That means everything in the lapply is getting ignored.

Thanks for your help.

Edit: turns out the issue was the absence of xlim and ylim parameters in the Plot function, thus making only the first set of points visible. By increasing the range of the axes all the points were visible.

Max
  • 1
  • 1
  • "Didn't work" can mean a lot of things in a `shiny` context. Are you seeing any output at all? Any errors either in the app itself or in the console? WIthout a working app, it's impossible to tell if the problem is with your data, with how you're handling it in general, or with how you're implementing it in `shiny`. A [minimal example](https://stackoverflow.com/help/minimal-reproducible-example) would really help. – phalteman Jan 19 '22 at 06:44
  • Woops sorry didn't include that. Will edit the post. – Max Jan 19 '22 at 13:26
  • Why do you think the lines following the `plot` call will have any influence on the plot? (hint: they do not) – ziggystar Jan 19 '22 at 13:33
  • Well normally adding the points, or lines function after the plot will add the data on the same plot. I was also trying to follow the solution in this answer: https://stackoverflow.com/a/53472859/17969666 – Max Jan 19 '22 at 13:40

0 Answers0