rmarkdown icon indicating copy to clipboard operation
rmarkdown copied to clipboard

R nb.html missing output when the output is shown inline in the RStudio

Open olechnwin opened this issue 2 years ago • 11 comments

The plot I have in the Rmd file is showing in Rstudio as inline output:

image

But when I clicked on the preview button, the plot is missing.

image

Unfortunately, I am unable to create a reproducible example.

olechnwin avatar Aug 21 '23 19:08 olechnwin

Unfortunately, I am unable to create a reproducible example.

Unfortunately without reproducible example, or at least a shared document or anything, it will be hard to help and look into this.

Lots of things can happen, and it could be linked to some state of your local environment.

You could try a whole new clean project in a new RStudio session to see if caching is the culprit here. Maybe starting fresh would solve it.

If you have no specific error message or anything, I don't know what could happen. We need more to be able to start looking into this.

cderv avatar Aug 22 '23 12:08 cderv

@cderv, Thank you so much for your reply. Is there a way I can have a log of what was run behind the scene when I press preview? Does it run knit? Maybe that way I can create a reproducible example.

I didn't create a project in RStudio. I was just creating an R notebook. I'll try creating a project.

If I start new it'll work but then after a while the same problem will happen. Let me think more on how to create a reproducible example.

Forgot to mention, if I re-run the chunk, the figure will then appear in the preview.

olechnwin avatar Aug 22 '23 12:08 olechnwin

Is there a way I can have a log of what was run behind the scene when I press preview? Does it run knit?!

I don't know what RStudio IDE is really logging on that matter. When you press preview for a .Rmd with html_notebook() output, it will not run knit() as when you render with rmarkdown::render().

AFAIK notebooks works by running the preview, and then you need to execute the chunk interactively on the source mode. And when you save it will update the preview with the save content. So basically, the result of the interactive execution is saved (cached) locally by the IDE, and this is what is included in the preview.

Preview for notebook is meant for rapid development, and so it does not render the document but use this trick. This means that first time you run preview, if you have run no chunk yet in the document, you will only see the text content in the HTML and no results.

More on notebook at https://bookdown.org/yihui/rmarkdown/notebook.html

Forgot to mention, if I re-run the chunk, the figure will then appear in the preview.

This lead me to believe this is a caching issue from the IDE. somehow the content of the chunk is seen as invalidating the result and you need to re-run the chunk interactively. This is how notebooks works as I explained above.

cderv avatar Aug 22 '23 12:08 cderv

AFAIK notebooks works by running the preview, and then you need to execute the chunk interactively on the source mode. And when you save it will update the preview with the save content. So basically, the result of the interactive execution is saved (cached) locally by the IDE, and this is what is included in the preview.

Yeah, it does sound like it somehow didn't save (cache) the result of interactive execution by the IDE.

Do you have any suggestion on what to check/fix for this cache issue from RStudio?

Thanks!

olechnwin avatar Aug 22 '23 12:08 olechnwin

Do you have any suggestion on what to check/fix for this cache issue from RStudio?

Unfortunately no. This could be a RStudio IDE related issue. Maybe you can try update to latest IDE if you are not using it already ?

cderv avatar Aug 22 '23 12:08 cderv

My RStudio is pretty new 2023.06.0 Build 421 but I'll try updating to the latest. Strangely, I tried to re-run the chunk but this time it didn't work. The plot never made it to the preview. Do you happen to know where is the cache for RStudio is?

olechnwin avatar Aug 22 '23 13:08 olechnwin

Do you happen to know where is the cache for RStudio is?

It should be local to the project.

If you could share a .nb.html or .Rmd source code, I could try on my side. Without being able to reproduce on my side, it is hard to help.

cderv avatar Aug 22 '23 13:08 cderv

Sure. Thank you so much for helping me with this issue. Appreciate it!

I am attaching my .nb.html and .Rmd. I added.txtat the end so I can upload them here.

atacseq_analysis_pax3foxo1_zebrafish.Rmd.txt

atacseq_analysis_pax3foxo1_zebrafish.nb.html.txt

This is the part in nb.hml that doesn't work:

<!-- rnb-source-end -->
<!-- rnb-chunk-end -->
<!-- rnb-text-begin -->
<p>Find overlap of peaks called by different algorithms.</p>
<!-- rnb-text-end -->
<!-- rnb-chunk-begin -->
<!-- rnb-source-begin eyJkYXRhIjpbIm92ZXJsYXAucGVha3M9ZmluZE92ZXJsYXBzT2ZQZWFrcyhtYWNzX3NoaWZ0X3BlYWssbWFjc19uZmNvcmV
fcGVhayxnZW5yaWNoX3BlYWspIiwibWFrZVZlbm5EaWFncmFtKG92ZXJsYXAucGVha3MpIl19 -->
<pre class="r"><code>overlap.peaks=findOverlapsOfPeaks(macs_shift_peak,macs_nfcore_peak,genrich_peak)
makeVennDiagram(overlap.peaks)</code></pre>
<!-- rnb-source-end -->
<!-- rnb-chunk-end -->
<!-- rnb-text-begin -->
<!-- rnb-text-end -->
<!-- rnb-chunk-begin -->
<!-- rnb-source-begin eyJkYXRhIjpbInNvdXJjZSBnbG9iYWxfdmFycy5zaCIsImNkICR3b3JrZGlyIiwib3V0ZGlyPSR3b3JrZGlyL25mY29yZV9
hdGFjc2VxX3J1bi9vdXRwdXQvYndhL21lcmdlZF9yZXBsaWNhdGUvZ2VucmljaC9wM2ZfaG9tZXIiLCJwZWFrZmlsZT0kd29ya2Rpci9uZmNvcmVfYXRh
Y3NlcV9ydW4vb3V0cHV0L2J3YS9tZXJnZWRfcmVwbGljYXRlL2dlbnJpY2gvcDNmX3BlYWtzLm5hcnJvd1BlYWsiLCJlY2hvICRvdXRkaXIiLCJlY2hvI
CRwZWFrZmlsZSIsIm1rZGlyIC1wICRvdXRkaXIiLCJzYmF0Y2ggXFwiLCIgLS1leHBvcnQ9cGVha2ZpbGU9JHBlYWtmaWxlLG91dGRpcj0kb3V0ZGlyIF
xcIiwiIHJ1bl9ob21lcl9tb3RpZi5zaCJdfQ== -->

I can see related files in cache directory but the dates are Aug 8. even though I rerun this part of code on Aug 22.

ll overlap_peaks*
-rw-r--r-- 1 cxt010 gdlab 232 Aug  8 16:13 overlap_peaks_2e0d2267ba04344b49d146bd56b8c926.RData
-rw-r--r-- 1 cxt010 gdlab   0 Aug  8 16:13 overlap_peaks_2e0d2267ba04344b49d146bd56b8c926.rdb
-rw-r--r-- 1 cxt010 gdlab 125 Aug  8 16:13 overlap_peaks_2e0d2267ba04344b49d146bd56b8c926.rdx

olechnwin avatar Aug 22 '23 14:08 olechnwin

I can see related files in cache directory but the dates are Aug 8. even though I rerun this part of code on Aug 22.

Did you try already what is mentioned in the documentation I linked previously ?

https://bookdown.org/yihui/rmarkdown/notebook.html#chunk-output

When code is executed in the notebook, its output appears beneath the code chunk that produced it. You can clear an individual chunk’s output by clicking the X button in the upper right corner of the output, or collapse it by clicking the chevron.

It is also possible to clear or collapse all of the output in the document at once using the Collapse All Output and Clear All Output menu items available on the gear menu in the editor toolbar (Figure 3.4).

If you want to fully reset the state of the notebook, the item Restart R and Clear Output on the Run menu on the editor toolbar will do the job.

cderv avatar Aug 22 '23 14:08 cderv

I've tried the clear individual output by clicking the X button but this doesn't work.

Clear all output also doesn't work.

I can't find how to fully reset the state of the notebook. This is all I see on my run menu image

olechnwin avatar Aug 22 '23 16:08 olechnwin

I see in your Rmd source code that you get cache=TRUE, so this means you are also activating the knitr cache feature for this one. This could be conflicting with the notebook feature maybe.

Did you try uncaching the chunk, or remove the knitr cache directory, or invalidate the cache (by modifiying the chunk a little).

To be clear, knitr cache is different than internal caching from html_notebook

cderv avatar Aug 23 '23 08:08 cderv