How to add specific text in a Shiny app?

Hi all

I am working on a Shiny app. Before that, I did some calculations on R Markdown. In R Markdown you can have a good text output.

eg:

**Mean** value of the TAT: **`r mean(df_TAT_filtered$TAT)` mins**. <br><br>
**Percent quantiles** expressed in minutes:

10%|50%|90%|95%
---|---|---|---
`r quantile(df_TAT_filtered$TAT, .10)`|`r quantile(df_TAT_filtered$TAT, .50)`|`r quantile(df_TAT_filtered$TAT, .90)`|`r quantile(df_TAT_filtered$TAT, .95)`

The following histogram will give an overview about the distribution of the TAT and is based on **`r nrow(df_TAT)`** samples.

This gave a good output in the R Markdown text section. Is it also possible to do such an code in Shiny (eg in the leftside panel in the UI)?

Thanks in advance!

library(shiny)
library(markdown)
library(knitr)
ui <- fluidPage(
 uiOutput("markdown")
)


mtext <- "**Mean** value of the Petal.Length: **`r mean(iris$Petal.Length)` mins**. <br><br>
**Percent quantiles** expressed in minutes:

10%|50%|90%|95%
---|---|---|---
`r quantile(iris$Petal.Length, .10)`|`r quantile(iris$Petal.Length, .50)`|`r quantile(iris$Petal.Length, .90)`|`r quantile(iris$Petal.Length, .95)`

The following histogram will give an overview about the distribution of the Petal.Length and is based on **`r nrow(iris)`** samples.
"


server <- function(input, output, session) {
  output$markdown <- renderUI({
    tf <- tempfile()
    knit(text=mtext,
         output=tf)
    
    HTML(markdown::markdownToHTML(file = tf))
  })
    
}

shinyApp(ui, server)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.