In VScode-R, how to close previous plots tab, when refreshing plots using dev.list()? - plot

I am using httpgd as the default graphic devide for R in vs code.
if I don't use dev.list(), it will open up new plots in the same tab everytime a new plot is generated.
If I use dev.list(), it will open up a separate tab for the new plot. But how do I close the tab which stores previous plots?
Thanks.

Related

R redirect all plots including any intermediate state to a file synchronously

How can I redirect all plots including any intermediate state to a file synchronously?
I want to automatically redirect plots to a file without using expressions like png(); xxx; dev.off(). Imagine a in function where users can provide random plotting scripts and I don't know which line of code they start to plot and which line end and how many plots. As long as they make a plot, I want to capture it. One option is to use options(device="png"), found from this post.
options(device="png") method will create an empty file named like Rplot001.png and when dev.off or another top-level plotting function is called, write to the file. So no intermediate state is saved.
What I want is more like the plots panel in Rstudio: when I make some low-level changes, the image file is updated immediately.
A simple example, I want to plot a point and add a title.
options(device="png")
plot(1)
At this point, the plot should be captured by a file automatically, let's name it Rplot001.png.
title("abc")
Then, the Rplot001.png is updated which contains the title.
The problem is when I do this, Rplot001.png is not written unless I manually call dev.off or open another plot.

Rendering multiple altair charts in a single cell of a jupyter notebook

I see in the troubleshooting guide to Altair that:
'If you are working in a notebook environment, the chart is only
displayed if the last line of the cell evaluates to a chart object'
I have a dictionary of several auto-generated altair charts. I want to show in one notebook cell, separately, all the charts I have created. I would like to do something like:
for k in graphs:
graphs[k].show() #or the equivalent of 'show this chart'
How can I do the equivalent of this? Currently I can only render a single chart in a cell by evaluating a single chart.
Use chart.display():
for k in graphs:
graphs[k].display()

Manipulate slider does not appear in 'plot'

Simple question: What prevents manipulate sliders from appearing in the 'plot' section of R Studio?
Let's take a very simple example, run in an Rmarkdown chunk:
manipulate(
plot(1:x), x = slider(1, 100)
)
In rmarkdown, this doesn't show the plot and slider in the 'plots' pane. Instead the plot shows below the chunk.
How do I make the manipulate functionality appear?
The answer is to choose the gear above the rmarkdown document and choose 'Chunk Output in Console'.

Paned plots in R notebook export

When editing an R notebook inside RStudio, if I create multiple graphical outputs in one R block, I get an icon for each plot, which I can click on to select which plot to look at:
I like that behavior, it's especially handy to click from one plot to another to compare changes between them.
However, when I render the notebook to HTML (e.g. by hitting the "Preview" button in the editor), the plots simply cascade down the page:
Is there a way I can get the former behavior in an exported document? Some option I can set, or a chunk of Javascript I can include, or something?

Print Dialogue for formated R Shiny Output

Using R-Shiny, I would like to be able to create a button that will open a print dialogue with formatted data and charts.
I do not want the button to print exactly what is displayed on the screen; instead, I would like it to print a layout I define specifically for that analysis.
What is the best way to format a set of analysis and outputs in R Shiny for high resolution printing?
How can I make the button open a print dialogue for the formatted output?
Would it be better to use Latex + Sweave to write a new report on button click, and have the resulting PDF opened by the browser?
If so, how could I do that?

Resources