R Shiny's problem - plotting multiple lines on the same chart

Currently, my code initially allows the user to choose which dataset they want (a choice of two). Then, based on what they choose, other build variables for the corresponding subsets of the data sets appear. This works great, except that I would like the plots to be overlapped on the same plot, and not separately, as they appear by default.

I have a default graph, plot_Total, and the other parameters in the datasets are looking at specific subsets of this. Therefore, it would be wise to have only one scatter.

output$plot_Total <- reactivePlot(function() { plot.new() plot.window(xlim=c(1850,2020), ylim = c(0,5000000)) axis(1) axis(2) title(main="Numbers over the years") title(xlab="Year") title(ylab="Number of people") box() points(dat$Year, dat$Total, col="red") lines(dat$Year, dat$Total, col="red") }) output$plot_subset1 <- reactivePlot(function() { lines(dat$Year, dat$subset1) }) output$plot_subset2 <- reactivePlot(function() { lines(dat$Year, dat$subset2) }) 

Why is this piece of code not working? It simply creates spaces for each (unwanted) graph, which says: "Error: plot.new has not yet been called." How to specify to add these lines to the default chart (plot_Total)?

+4
source share
1 answer

Update: playing with the code for the graph on the shiny homepage, I realized that I had to do this:

  output$plot_Total <- reactivePlot(function() { plot.new() plot.window(xlim=c(1850,2020), ylim = c(0,5000000)) axis(1) axis(2) title(main="Numbers over the years") title(xlab="Year") title(ylab="Number of people") box() points(dat$Year, dat$Total, col="red") lines(dat$Year, dat$Total, col="red") if (input$RC) { lines(dat$Year, dat$dat)} }) 

This differs from my source code in two ways. First, the conditional is added as one line within the same reactive set function. Secondly, I created a new data.frame that contains only a subset of RC. This did not initially work as an input $ dat $ RC, but when RC is its own framework, it works as an input $ RC.

Points for Chase to control me in the right direction!

+7
source

Source: https://habr.com/ru/post/1445238/


All Articles