How to embed a shiny application into an Rmarkdown html document
Asked Answered
C

3

7

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.

Castera answered 17/7, 2017 at 16:57 Comment(2)
link Read the comments sectionMardis
@Mardis I am currently using the Inline approach, but either get the shiny app working without html, or the html working, without the shiny app. I think I may have some misunderstanding here. May you show me the way?Castera
D
4

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

Defection answered 19/7, 2017 at 5:0 Comment(1)
Thank you for your answer, But I still don't get it. May you give me an example? Do I need to add a codeblock containing the ui and server component? Do I need to call the function shinyApp(ui,server) before? Do I need to put the shiny code in a different folder / project or the very same markdown file? Where do I get the URL from?Castera
A
2

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.

Adiaphorous answered 18/9, 2017 at 9:24 Comment(0)
B
0

'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.'

https://shiny.posit.co/r/articles/build/interactive-docs/

Belldame answered 12/12, 2023 at 6:26 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.