Reputation: 8577
I would like to display some R code on my shiny app. Therefore, I used verbatimTextOutput
but I can't find a way to break lines and to display paragraphs of code.
This solution (Outputting multiple lines of text with renderText() in R shiny) only works with the HTML
function and there is no way (to my knowledge) to mix verbatimTextOutput
and htmlOutput
.
I can display code with tags$code
but it is not the appearance I would like (I would prefer the grey background).
Here's a reproducible example :
library(shiny)
ui <- fluidPage(
mainPanel(htmlOutput("base", placeholder = FALSE))
)
server <- function(input, output) {
output$base <- renderUI({
tags$code(HTML(paste("just", "some", "code", sep = '<br/>')))
})
}
shinyApp(ui = ui, server = server)
Upvotes: 4
Views: 1980
Reputation: 8936
I have previously used cat()
for this purpose:
library(shiny)
ui <- fluidPage(
mainPanel(verbatimTextOutput("vtout"))
)
server <- function(input, output) {
output$vtout <- renderPrint({
cat("just", "some", "code", sep = "\n")
})
}
shinyApp(ui, server)
Upvotes: 10