Reputation: 14212
I am trying to insert some line breaks using cat
and \n
into some text output using shiny
.
Here are the relevant parts of my ui.R
and server.R
.
let's say I wanted to get the results of a t-test, and have a separate line for 't', 'df' and 'p-value'
I'm using shinydashboard layout.
Group_A <- 1:13
Group_B <- 8:19
box(title = "T-test results:", status = "primary", textOutput("text3"), width=3)
output$text3 <- renderPrint({
obj <- t.test(Group_A, Group_B)
cat("t = ", round(obj[[3]],3), "\n, df = ", round(obj[[2]],3), "\n, p-value = ", round(obj[[3]],5))
})
This output is shown in the image below:
As you can see, the output is across the screen left to right separated by a comma. Because I want to add a number of results, I would like them to go top to bottom on the screen with a line break after each value.
Does anyone know how to do this in shiny
?
Upvotes: 1
Views: 8588
Reputation: 1
Use a paragraph tag with nothing inside like tags$p("a"),
see here
Upvotes: 0
Reputation: 19970
Here is a solution using renderUI
and htmlOutput
library(shiny)
Group_A <- 1:13
Group_B <- 8:19
runApp(
list(
ui = fluidPage(
htmlOutput("text3")
),
server = function(input, output){
output$text3 <- renderUI({
obj <- t.test(Group_A, Group_B)
HTML(
paste0("t = ", round(obj[[3]],3), '<br/>',
"df = ", round(obj[[2]],3), '<br/>',
"p-value = ", round(obj[[3]],5))
)
})
}))
Upvotes: 4