Insert a line breaks into text output in brilliant form with cat

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 am using a shinydashboard layout.

sample data

 Group_A <- 1:13 Group_B <- 8:19 

Ui

 box(title = "T-test results:", status = "primary", textOutput("text3"), width=3) 

Server

 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:

enter image description here

As you can see, the output on the screen from left to right is separated by a comma. Since I want to add some results, I would like them to go top down on the screen with a line break after each value.

Does anyone know how to do this in shiny ?

0
source share
2 answers

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)) ) }) })) 
+2
source

Use a paragraph tag without anything inside, like tags$p("a"), see here

0
source

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


All Articles