I have been trying to wrap a chunk of text to be presented in a desired manner. I have tried to wrap the text in
tags$div(). But it throws me an error
library(shiny)
#> Warning: package 'shiny' was built under R version 4.0.5
ui = fluidPage(
textOutput("tx1"), tags$br(),
textOutput("tx2"), tags$br()
)
server <- function(input, output){
output$tx1 <- renderText(
tags$div("Note:
Some text 1
More text 2
")
)
output$tx2 <- renderText(
"Note:
Some text 1
More text 2
"
)
}
shinyApp(ui, server)
#>
#> Listening on http://127.0.0.1:7386
#> Warning: Error in cat: argument 1 (type 'list') cannot be handled by 'cat'
I am getting -
Error in cat: argument 1 (type 'list') cannot be handled by 'cat'
I believe one way you could do this would be with paste. Such as:
renderText(
paste('Note:', 'Some text 1', 'More text 2', sep = '\n')
)
You probably want to drop any tags$... in your server, unless you are specifically trying to render a UI element using renderUI. That's probably overkill in this case - I'd just drop the tag and put the function call that I wrote above into your renderTexts.
I think I have solved it by putting it into the UI.
library(shiny)
#> Warning: package 'shiny' was built under R version 4.0.5
ui = fluidPage(
textOutput("tx1"), tags$br(),
tags$ul(
"Note:",
tags$li("Some text 1"),
tags$li("More text 2")
),
textOutput("tx2"), tags$br()
)
server <- function(input, output){
output$tx2 <- renderText(
"Note:
Some text 1
More text 2
"
)
}
shinyApp(ui, server)
#>
#> Listening on http://127.0.0.1:3230