title: Highlight text based on list in R shiny
body: <p>I would like to highlight/color part of a string based on a list in R shiny. I have the following code:</p>
  
  <pre><code>library(shiny)
  
  
  ui &lt;- fluidPage(
  
        mainPanel(
          fluidRow(
            box(title="text",status="primary", solidHeader = TRUE, align = "left", width = 4,
                verbatimTextOutput("text"))))
  )
  
  server &lt;- function(input, output) {
  
     output$text &lt;- renderText({
  
       print("ABCDFGHIJKLMNOPQRSTUVWXYZABCDFGHIJKLMNOPQRSTUVWXYZABCDFGHIJKLMNOPQRSTUVWXYZABCDFGHIJKLMNOPQRSTUVWXYZABCDFGHIJKLMNOPQRSTUVWXYZABCDFGHIJKLMNOPQRS")
  
     })
  }
  
  
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p>How can I color/highlight parts of the string using a list:</p>
  
  <pre><code>highlight &lt;- c("GHIJ", "MNOP", "STUV")
  </code></pre>
  
  <p>The list changes based on user input. </p>
  
  <p>EDIT: I was able to highlight specific parts of the string using the following code:</p>
  
  <pre><code>library(shiny)
  library(magrittr)
  library(tableHTML)
  
  
  ui &lt;- fluidPage(
  
    mainPanel(
      fluidRow(
        box(title="Sequence",status="primary", solidHeader = TRUE, align = "left", width = 6,
          htmlOutput("text")),
          tags$style(type="text/css", "#text {word-break: break-all;}")))
  )
  
  
  server &lt;- function(input, output) {
  
    output$text &lt;- renderText({
  
      text2 &lt;- c("ABCDFGHIJKLMNOPQRSTUVWXYZABCDFGHIJKLMNOPQRSTUVWXYZABCDFGHIJKLMNOPQRSTUVWXYZABCDFGHIJKLMNOPQRSTUVWXYZABCDFGHIJKLMNOPQRSTUVWXYZABCDFGHIJKLMNOPQRS") 
      text2 %&lt;&gt;% stringr::str_replace_all(c('MNOPQR' = '&lt;span style="background-color:yellow"&gt;MNOPQR&lt;/span&gt;'))
  
  
  
  
      print(text2)
  
    })
  }
  </code></pre>
  
  <p>I have a big list of strings that I want to highlight that changes based on the user input. I want to wrap the str_replace_all function into a loop looking up all strings in the list. </p>
  
  <p>Something like this:</p>
  
  <pre><code>words &lt;- c("ABCD", "MNOP", "GHIJ")
  
      for (word in words){
  
      text2 %&lt;&gt;% stringr::str_replace_all(c('word' = '&lt;span style="background-color:yellow"&gt;word&lt;/span&gt;'))
  
      }
  </code></pre>
  
  <p>but I do not get it to work.</p>