Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to insert new line in R shiny string

Tags:

r

shiny

In shiny, I have the following:

  output$sequenceText <- renderText({     showSequence()   })  showSequence <- reactive({   selectedSeqs <- as.numeric(input$sequenceSelect)   resultString <- ""   currentString <-""    for(i in selectedSeqs){     currentString <- paste(i, toString(myProts[i]), sep = ":")     resultString <- paste(resultString, currentString, sep = "\n")   }   return(resultString)  }) 

However, it doesn't seem that the new line character is respected. How do I fix that?

Thanks!

like image 404
user1357015 Avatar asked Oct 14 '14 18:10

user1357015


2 Answers

To my knowledge, there are only two options to display multiple lines within shiny. One way with using verbatimTextOutput which will provide a gray box around you text (personal preference). The other is to use renderUI and htmlOutput to use raw html. Here is a basic working example to demonstrate the results.

require(shiny) runApp(   list(     ui = pageWithSidebar(       headerPanel("multi-line test"),       sidebarPanel(         p("Demo Page.")       ),       mainPanel(         verbatimTextOutput("text"),         htmlOutput("text2")       )     ),     server = function(input, output){        output$text <- renderText({         paste("hello", "world", sep="\n")       })        output$text2 <- renderUI({         HTML(paste("hello", "world", sep="<br/>"))       })      }   ) ) 

This yields the following figure:

enter image description here

like image 180
cdeterman Avatar answered Sep 17 '22 09:09

cdeterman


How about

  output$text2 <- renderUI({     HTML('hello <br> world')   }) 
like image 30
martin Avatar answered Sep 21 '22 09:09

martin