Printing print lines using sprintf - with shiny

I am trying to make line breaks while printing. A.

here is my code:

temp <- LETTERS[1:11] print(sprintf("Rank %s = %s \n", 1:11, temp)) 

exit:

 [1] "Rank 1 = A \n" "Rank 2 = B \n" "Rank 3 = C \n" "Rank 4 = D \n" "Rank 5 = E \n" "Rank 6 = F \n" "Rank 7 = G \n" "Rank 8 = H \n" "Rank 9 = I \n" [10] "Rank 10 = J \n" "Rank 11 = K \n" 

I naively thought that \n made a line break. My desired result:

 "Rank 1 = A" "Rank 2 = B" "Rank 3 = C" "Rank 4 = D" ... etc. 

EDIT:

Pascal comment tells me that it works with cat

 cat(sprintf("Rank %s = %s \n", 1:11, temp)) 

I use this code inside renderText inside brilliant. print will return text, but I cannot get cat to return text.

In this case, is there anywhere to generate the required line breaks without using cat ?

+5
source share
1 answer

You can change renderText to renderUI and htmlOutput as described here . the script may be something like

 library(shiny) runApp( list( ui = fluidPage( htmlOutput("text1") ), server = function(input, output){ output$text1 <- renderUI({ temp <- LETTERS[1:11] HTML( paste0(sprintf("Rank %s = %s", 1:11, temp), collapse = "<br>") ) }) })) 

Result

enter image description here

-1
source

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


All Articles