Is there a way to highlight text search output with 'includeHTML' and without using Data Table package?

I created a text search but I need to highlight the text in HTML page when user searches for a sentence clicking on the sentence outputted as shown in screenshot . the right corner one is HTML file while middle column gives sentence output from text .So clicking on the sentence on middle column, one can jump to that line in HTML file but I want that line to be highlighted

library(quanteda)
library(shiny)
library(tidyverse)
library(shinydashboard)
library(shinythemes)
library(purrr)


war <- readLines("war.txt")

war_corpus <- corpus(war)

sentences <- tokens(war_corpus,what="sentence")

make_sentences <- function(word) {
                  grep(word,sentences,value= T)}

sentence_line <- function(word) {
                  grep(word,sentences,value= F)


ui<- shinyUI(fluidPage(theme = shinytheme("superhero"),
            
  
  # Application title
  dashboardBody(
    img(src='spsimage.jpg', align = "left"),style = "padding-top:20px",
    
    #fluidRow(HTML("<strong>  Search Bar")),
    br(),
    br(),
    #fluidRow(HTML(" <strong>Date: 07-29-2020</strong>") ),
    br(),
    #fluidRow(
    br(),
    br(),
    br(),
    br(),
    
    #tags$head(
      #tags$style(
        #"body {height: 90vh;overflow-y: auto;}"
      #),
      
    fluidRow(
             #style = "max-height: 90vh; overflow-y: auto;" ,
        column(width = 2,
              h5(HTML("<strong>Enter a word.Click \"SEARCH\" </strong>")),
        wellPanel(
            textInput("inputString","Enter a word here",value=" "),
            submitButton("SEARCH"),
        
        )),
          
        column(width= 3,style = "max-height: 90vh; overflow-y: auto;",#creates scroll bar
               h4("Search Results"), #h4 is for heading font size 
               wellPanel(            #places output inside a panel
               tags$style("#mytext { white-space: pre-line; }"),#css text format
               htmlOutput("mytext")# earlier verbatimetextoutput
               )),
        
       column(width = 7,offset = 1.5,style = "max-height: 90vh; overflow-y: auto;",
               h6("Uploaded File"),
               wellPanel(
                 tags$style(),
               htmlOutput("showfile"))
        )
    )

        )#Mainpanel
     
  
    )#fluidpage
  )#shinyUi


server <- function(input, output, session) {
  output$mytext <- renderUI({
    
    lapply(1:m, function(i){
    res <- make_sentences(input$inputString)[i]
    res1<- sentence_line(input$inputString)[i]
    
    tagList(
        tags$a(href=paste('#',res1,sep=""),res1),tags$div(res))
    }
    )
  
  }
)
    
    output$showfile <- renderText({
     includeHTML("www/final_tokens.html")
  })
}

shinyApp(ui,server)

using Data Table package and using dataTableOutput or renderDataTable has been giving me error as it says HTML file is not 2x2 matrix

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.