How to visualize a table and math in Rmarkdown when called from a Shiny application

I have a Rmarkdown file ( info.rmd ) that looks like this:

 --- title: "Information" theme: yeti date: "4/1/2017" output: html_document --- ## R Markdown This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>. ```{r echo = FALSE, results = 'asis'} library(knitr) kable(mtcars[1:5, ], caption = "A knitr kable.") ``` ## Formulation Here is where we formulate $$\sum_{i=1}^n X_i$$ 

And ShinyApp, which calls Rmarkdown as follows:

server.R

contains this

  output$markdown <- renderUI({ HTML(markdown::markdownToHTML(knit('info.rmd', quiet = TRUE), fragment.only=TRUE)) }) 

ui.R

contains the following:

  fluidPage(uiOutput('markdown')) 

But how did the table and math look like this?

enter image description here

What is the right way to do this?


When running offline outside of Shiny, info.rmd creates the table correctly:

enter image description here


I tried this in ui.R

  includeHTML("info.html") 

How to correctly display the html file, but prevents tabPanel() and reactivity in other tabPanel() to work.


Update

Here is the new result after @Nice's solution:

enter image description here

+5
source share
2 answers

If you use fragment.only , CSS and JS are not included, and the table / equation is not styled.

One easy way to do this is to include full HTML with a title in the iframe so that it does not interfere with the rest of your application.

 output$markdown <- renderUI({ tags$iframe(src='info.html',width="100%",frameBorder="0",height="1000px") }) 

The info.html file should be in the www folder of your application. You can adjust the width and height of the iframe by changing the parameters in tags$iframe .

You can change the width of the main container in the iframe using CSS. If you add this to your info.rmd file:

 ```{r results="asis",echo = FALSE} cat(" <style> .main-container.container-fluid { max-width: 100%; padding-left:0px; } </style> ") ``` 
+4
source

Editing the shiny part of the server as follows should help:

 output$markdown <- renderUI({ markdown::markdownToHTML(knit('info.rmd', quiet = TRUE), fragment.only=TRUE) withMathJax(includeHTML("info.html")) }) 

Alternatively, you can also do the following:

 output$markdown <- renderUI({ markdown::markdownToHTML(knit('info.rmd', quiet = TRUE), fragment.only=TRUE) withMathJax(includeMarkdown("info.md")) }) 
0
source

Source: https://habr.com/ru/post/1266208/


All Articles