1

I am trying to highlight some error in a file by changing the format (color or bold...) of a text according to a condition in a R markdown sheet. I checked at this topic Conditional font color R Markdown but as I am working in a "shiny" context it needs to be embedded in a renderText. So I tried different possibilities:

```{r}
output$text <- renderText({ 
  if(length(test) > 0) {
    div(paste("There is a value missing line(s):", paste(test[[1]], sep = " ", collapse = " ")), style = "color = red")
  } else {
    "There is no missing value"
  }
})
```

r textOutput('text')`

I also tried:

output$text <- renderText({ 
  if(length(test) > 0) {
    paste("**There is a value missing line(s):", paste(test[[1]], sep = " ", collapse = " "), "**"))
  } else {
    "There is no missing value"
  }
})

or that :

output$text <- renderText({ 
  if(length(test) > 0) {
    paste(eval(parse(text = "**")), "There is a value missing line(s):", paste(test[[1]], sep = " ", collapse = " "), eval(parse(text = "**")))
  } else {
    "There is no missing value"
  }
})

and

output$text <- renderText({ 
  if(length(test) > 0) {
    text.Toprint <- paste("** There is a problem of number of values line(s):", paste(test[[1]], sep = " ", collapse = " "), "**")
    HTML(text.Toprint)
  } else {
    "There is no missing value"
  }
})

and finally:

output$text <- renderText({ 
  if(length(test) > 0) {
        text.Toprint <- paste("<b> There is a mistake column. Check the line:", paste(test[[1]], sep = " ", collapse = " "), "</b>")
    HTML(text.Toprint)
  } else {
    "There is no missing value"
  }
})

But none of them are working.

Do you have some idea or any documentation to advise ?

Thanks a lot and good evening :)

Cha

neilfws
  • 32,751
  • 5
  • 50
  • 63
CharlotteS.
  • 355
  • 1
  • 12
  • Isn't [this what you're after](https://stackoverflow.com/questions/24049159/change-the-color-and-font-of-text-in-shiny-app)? – Roman Luštrik Feb 19 '18 at 22:13
  • Thanks Roman but actually the color or the formatting is only on one condition, e.g. if the length is > 0 then the text is in red/bold otherwise it's black. Does it make sense ? – CharlotteS. Feb 19 '18 at 22:19

0 Answers0