How to update with content containing multiple lines using updateTextAreaInput


#1

I need to do

updateTextAreaInput(session = session,
inputId = contextID,
value = content)

where content has multiple lines.
Whether content is a string with'\n' inserted or a character vector with length > 1,
the textarea will show '\n' instead of newlines.

Any ideas, friends?


#2

It actually shows new lines with '\n' for me. Tested on Firefox and Edge

library(shiny)

ui <- fluidPage(
   
   titlePanel("Text Area update"),
   
   sidebarLayout(
      sidebarPanel(
         actionButton('btnUpdate', 'Update')
      ),
      
      mainPanel(
        textAreaInput(inputId = 'testInput', 'Test', value = '', height = '400px')
      )
   )
)

server <- function(input, output, session) {
  observeEvent(input$btnUpdate, {
    updateTextAreaInput(session = session,
                        inputId = 'testInput',
                        value = 'abcd\ncde')
  })
}
shinyApp(ui = ui, server = server)

#3

Ha, the joke's on me,
I was reading the new text from a file with '\n' in strings,
and somehow ended up with '\\n' instead.
Thanks for your help!