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)?
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)