What I do
I'm translating "OpenIntro::Introduction to Modern Statistics Tutorials" into German. I use the downloaded .zip tutorials to do so: https://openintrostat.github.io/ims-tutorials/. The tutorials are learnr::tutorials written as .Rmd files. In tutorial 3 lesson 8 I'm facing an Error I'm unable to solve.
Problem
While doing the tutorial you face the plot_ly() function four times. But it only works one time as expected (in one session). Using the function a second, time an error message says: "verbose must be TRUE or FALSE". In the RStudio "Render"-pane: "Quitting from lines 11-44 [ex5-babies-plotly] (exercise.Rmd)". This points to the {r setup} but also makes me wonder because verbose = FALSE.
knitr::opts_chunk$set(fig.align = "center",
fig.height = 3,
fig.width = 5,
echo = FALSE,
message = FALSE,
warning = FALSE,
verbose = FALSE)
Things I tried an checked
Running plot_ly several times in RStudio is no problem.
Running plot_ly in the original on shinyapps several times works as well.
I tried knitr::opts_chunk$set(verbose = FALSE) as the first line in the chunk where the plot_ly()function is used. Didn't work!
Everything is up to date.
Questions
I don't get why it only works the first time. Do you have an explanation? Do you know a way to solve this problem?
I apologize for passing you bad information. I must have left a cache somewhere making me think that the solution was the package unloading when clearly it is not.
However, it did tell me that something I did did actually fix it... since you messaged me I've been trying to figure out what I did that did work.
The BLUF or more trendy TL;DR:
Call
library(data.table)when you initially call the necessary libraries in your setup chunk.Yes, that's it. (For real this time...)
How did I get there?
While Plotly apparently imports
data.table. When Plotly imports it, neither the environments of RMD nor Shiny prerendered pull the default R options fordata.tableinto your script.If you recall, I mentioned that I found a verbosity error having to do with
data.tableand I dismissed it.... in my original answer. .In the viewer/browser, I rendered any two of the Plotly plots (how you directed me to recreate the error about verbosity).
For example, chunk
ex5-babies-plotly- 3D visualization, then chunkex10-babies-plotly-two- Drawing parallel planes in 3D.After attempting to render the second plot, so that the error occurs, I deleted
plot_ly(...)and replaced it withrlang::last_trace()(If you don't delete plotly it errors again before giving you the output oflast_trace)This allows us to see the rest of the error message...reading beyond that isn't necessary. (What
last_tracereturns starts with..alloccol...-- what was discussed in that link I included in my original answer)Once the error is present, run
options()in your R console, then in any interactive exercise, you'll see severaldatatableoptions in the console and none in your RMD.For me, R returns 15.
(The code for that without the picture:
length(options()[startsWith(names(options()), "datatable")]))The exercise returns zero.
After you add
library(data.table)to your setup chunk and run the document, you can check the options again. You'll see it now matches the R console at 15.Originally I wrote....(doesn't work)
This does not address the actual problem, it's a workaround.
The only corresponding information regarding a fix placed the blame on the package
data.table. (You can read about that here.) Obviously,data.tableisn't the issue. Unfortunately, I am not entirely sure what the problem is.The fix I offer is to unload the Plotly library between each call to plot. You can leave these chunks invisible, so the reader won't know they are there. I would encourage you to leave comments for yourself, so that you remember why these are here, though.
Here is an excerpt from the English version, along with the fix I offer.
Notice that I've set
include=FALSEso that it isn't visible to the user. Additionally, I didn't call the library after unloading it again since it's called in the code visible to the user.