Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed a shiny application into an Rmarkdown html document

I would like to create an html document with RMarkdown, containing text, Rcode and somewhere in between a shiny application.

  • I thought of using asis=TRUE for the shinyApp(ui, server) block, but RStudio only renders the Rmd file, if I add runtime: shiny to the YAML-Header.
  • If I do so, no html is created, but I can move to browser view.
  • If I look at the source code in the browser view , I still don't see the entire html code.
  • If I check the generated temporary file, I was not able to find the html file representing the entire RMarkdown document.

How to generate html-code from the shinyApp function? Or: How to generate an html file, from RMarkdown containing a shiny app instead of e.g. a plot

I hope you have some idea for me.

like image 591
Martin Avatar asked Jul 17 '17 16:07

Martin


2 Answers

I don't really understand what you mean by "a shiny application". If you have already set up a server side application, i.e. others can assess your application via url, you can try the following approach.

see https://bookdown.org/yihui/bookdown/web-pages-and-shiny-apps.html, second paragraph

A related function is knitr::include_app(), which is very similar to include_url(), and it was designed for embedding Shiny apps via their URLs in the output.

enter image description here

like image 157
Zhuoer Dong Avatar answered Sep 22 '22 11:09

Zhuoer Dong


If I understand your question correctly then maybe the following URL could be of help for you:

https://bookdown.org/yihui/rmarkdown/shiny-start.html

As you can see: You don't have to follow the Shiny skeleton template. The only thing to do: You have to add the line runtime: shiny into the YAML-header and publish the .Rmd file in the normal way, e.g. you have to include a standard r code snippet in your RMarkdown document where you can write your shiny code.

I hope this is helpful.

like image 34
petzi Avatar answered Sep 23 '22 11:09

petzi