1

In my Markdown file I use Shiny widgets to set some parameter. Add the end of the document some reactive text should be shown, depending on the choosen parameter, changing when a parameter is changed. This text should be formatted with linebreaks. Output format is HTML. The following minimal example shows my approach, the screenshot below the outcome. Unfortunatelly without linebreaks.

How can I archieve linebreaks in reactive textoutput in R-Markdown?

---
title: 'Minimal example'
runtime: shiny
output: 
  html_document

---


```{r setup, include=FALSE}
library(knitr)
library(shiny)
knitr::opts_chunk$set(echo = F)
```


```{r}
selectInput("input1", label = "Input1",
              choices = 1:5, selected = 1)

selectInput("input2", label = "Input2",
              choices = 1:5, selected = 1)

```

```{r}
### Generate Parameter for report
renderText({
        HTML(paste('Input1:', input$input1, '<br> Input2:', input$input2))
})

renderText({
        paste('Input1:', input$input1, ' \\n Input2:', input$input2)
})

renderText({
        paste('Input1:', input$input1, '  \n Input2:', input$input2)
})

renderText({
        cat(paste('Input1:', input$input1, '  \n Input2:', input$input2))
})
```

HTML Output

1 Answer 1

2

Use renderUI in combination with HTML() instead:

renderUI({
        HTML(paste('Input1:', input$input1, '<br> Input2:', input$input2))
})
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Are you aware of a way to have sequences like '\n' considered?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.