Hello All,
I am working on a commenting system with shiny where a user can enter a comment which I then wish to eventually display within a uiOutput block. Does anyone have any suggestions how this is best done so that the formatting in the output is as entered in the textarea?
Here is a minimal working example with my current issues described below (note I need the tagList() call as I add some more meta-data)
ui.R:
library(shiny)
shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
tags$textarea(id="my_textarea", rows=5, "Leave a comment...")
),
mainPanel(
uiOutput("my_output")
)
)
))
server.R:
library(shiny)
shinyServer(function(input, output) {
output$my_output <- renderUI({
txt <- input$my_textarea
tagList(
tags$p("The comment is:"),
shiny::HTML(gsub("\n", "<br/>", txt))
)
})
})
My problem is that this is a hack as entering html tags such as "<br/>" in the text area creates a new-line in the output.
Does anyone have a solution to display the text exactly as it is shown in the textarea box. Preferably this solution should not enclose the comment within <pre>...</pre> as this won't lead to nice line-wrapping.
Thank you very much in advance,
Adrian
Here my sessionInfo()
> sessionInfo()
R version 3.3.0 (2016-05-03)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04 LTS
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=de_CH.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=de_CH.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=de_CH.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=de_CH.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] shiny_0.13.2
loaded via a namespace (and not attached):
[1] R6_2.1.2 htmltools_0.3.5 tools_3.3.0 Rcpp_0.12.5 jsonlite_0.9.20 digest_0.6.9
[7] xtable_1.8-2 httpuv_1.3.3 mime_0.4