Paned plots in R notebook export - r

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?

Related

Render all markdown cells in a Jupyter notebook at once

Is there a convenient way to render all markdown cells in a Jupyter notebook at once without running the code cells?
I find it quite annoying that while moving through my notebook and doing some little corrections the markdown cells "loose" their formatting. Is there an extension or a command with which I can "run" (i.e. render) all and only the markdown cells? If not, is there a way to at least update the table of content from the markdown cells. My table of content is realized via nbextensions.
You could use JupyterLab which provides a Render all Markdown cells action if you are not limited to plain Jupyter notebooks. Doing this programmatically within the notebook seems to be not trivial to do as we can derive from this GitHub issue. We might be able to implement this ourselves, but I am not aware of any resources that provide something similar.

How to capture a cell's output for use in another cell?

In org-mode, I can name the output of a code block and include it elsewhere in the document.
Is it possible to do this (or something similar) in a colab .ipynb file, or within a Jupyter notebook in general?
For example, I can make a cell with some Python code that generates a plot:
import matplotlib.pyplot as plt
plt.plot([0,2,1,4,9])
After executing, the plot appears below the code cell. So far so good.
But how do I capture this plot and to use it elsewhere in the notebook?
My hope is there is some syntax so that I can include the plot in a markdown cell, for example:
# this is my title
As you can see, the numbers go up and down in the plot:
![][some_magic_link_here]
Here is some more text to explain the plot.
Does such a feature exist in colab?
Good news - embedding an image in another markdown cell is self-service. Here's an example:
Full notebook:
https://colab.research.google.com/drive/1PF-hT-m8eZN2CBzFkMp9Bvzj9pSBQVYn
The key bits are:
Using IPython.display.Markdown is order to programmatically construct the markdown.
In addition to rendering, save the matplotlib figure using savefig.
Include the image data in the markdown after base64 encoding.

Changing keywords to highlight in an RMarkdown document

I have been writing a document in bookdown where within the *.Rmd file I call a figure by using the following syntax
\#ref(fig:MyFigureName)
This differs slightly from the notation that you would use in a normal RMarkdown file exporting to latex which would be
\ref{fig:MyFigureName}
The issue I am running into is that when I write something in bookdown the function calling the Figure is not being highlighted properly (see image below).
I have imported my own rsTheme (which is from my understanding, basically a .css file) but I don't see an option to add keywords to highlight.
But I would like for the entire function to be colored differently from the inline text (Photoshop version of desired output shown below)
Does anyone know how I would edit my *rsTheme file in order to accomplish this?
Thanks!

Hide R code chunks from outline view in RStudio

When writing .rmd or .Rnw reports in RStudio, the outline view shows both code chunks and regular sections. While code chunks appear italic, regular sections do not. However, writing large reports with many similar named chunks will lead to a really bulky outline view with many similar labels.
Is there currently a way to turn one of them off? Either regular sections or the code chunks.
As per my comment: global options -> Rmarkdown -> show in document outline change to show sections only

R Studio/R Accessing Blocks of Previously Run Code

Is there a way to display past commands in R/R Studio?? I know in R Studio there is a shortcut (CTRL+UP Arrow) that allows you to see past lines you have ran. But this shortcut only allows you to access only a single line, not a block of previously run code. Is there a package, or some way in R to display and select blocks of past code in R/R Studio?
Here you can find a description of the panes in R Studio, including the "history" pane.
There you can select several lines and paste them into the code.
Also, you can use the command savehistory() to save your history in a file you can the modify. If you want to choose the name of the file to be saved, use
savehistory(file = filename)
The same option is available in the basic R GUI (MS Windows), with "Save history" in the "File" menu (as a .RHistory file). Then, you can open it with any text editor and modify your history to make a script.
To see a specific number of lines, you can use history(25) (for 25 previous lines).

Resources