Distributing a Rmarkdown+Shiny document for easy access

I have an Rmarkdown doc with lots of embedded interactive shiny components and equations in TeX.
Works terrific! Convenient to edit the prose with Rmarkdown, and the shiny components can be interleaved freely. (In fact, I have shiny-inside-Rmd-inside-shiny-inside-Rmd, & it works great!)
Just click the "Run Document" button, then in the Preview Window click "Open in Browser".

how can I make it easily available to a user/student?
Goal: to do, in a function call or shell command,
the equivalent of "Run Document" followed by "Open in Browser".
(You need "Open in Browser" because
the layout in viewer is so different that the viewer is useless.)

I tried wrapping the whole thing inside a shiny app wrapper. It "works", but (a) the Rmarkdown table-of-contents navigator doesn't appear and (b) some shiny components (including all plots) in the Rmarkdown doc don't appear and all reactivity is broken.

I tried writing a few lines using rmarkdown::render(runtime='shiny') expecting to use httpuv and browseURL(), but no good. It fails because the shiny output input and session objects are not in scope. Yet via some magic behind "Run Document", they are, and the application runs fine.

Trying to see how httpuv::startServer works, but a little (or a lot) beyond me at this point.
If I could only locate the code behind the "Run Document" button, that would help a lot.

Ideas welcome!

From Shiny – Introduction to interactive documents:

Sharing interactive documents

Interactive documents are a type of Shiny app, which means that you can share them in the same way that you share other Shiny apps. You can

  1. Email a .Rmd file to a colleague. He or she can run the file locally by opening the file and clicking “Run Document”
  2. Host the document with Shiny Server or Shiny Server Pro
  3. Host the document at ShinyApps.io

Note: If you are familiar with R Markdown, you might expect RStudio to save an HTML version of an interactive document in your working directory. However, this only works with static HTML documents. Each interactive document must be served by a computer that manages the document. As a result, interactive documents cannot be shared as a standalone HTML file.

You might also consider moving this to the shiny category, since it sounds like the issues you're facing are more related to the fact that your document has embedded shiny components than to Rmarkdown itself (it's a tossup though)! :slightly_smiling_face:

1 Like

Thanks for your response. Yes, I've placed many shiny apps at shinyapps.io, it's a wonderful resource!

The e-mail route won't work-- the app requires installation of the entire package
(which is at www.github.com/professorbeautiful/T15lumpsplit ), so that many
supporting files -- js pdf R and other Rmd -- are available.
If I ask you to retrieve the package, build it in RStudio including installing
the imports, open the file inst/T15lumpsplit/Bias,variance,smoothing,shrinking.Rmd
click Run Document and then click Open in Browser...
... would you do it? How many would? You know, that younger generation, so impatient.

I suspect that if all the shiny code were moved into wrapper shiny app,
the interactivity would work fine... but the shiny components would be in the wrong places.
I use functions to ease re-use of the same type of component in many places, each one
containing both server and ui code, all positioned nicely where they belong
amongst the markdown text. Ooo, as an author I love it.
Therefore, I don't think shiny has an answer for me.
But still I like your suggestion to move my question to #shiny.

I'd like to locate that Run Document callback code from the RStudio repository,
but I can't find it. In that sense it's an #R-Markdown question.

Thanks again for taking the time.

Wouldn't be my first pick either. Like I said, just quoting directly from the source.