I created a text search whereby searching for a word, displays all the relevant sentences having that word in them. I want to create a loop which displays all possible sentences from search in Shiny.However I am getting just first sentence of the output
library(quanteda)
library(shiny)
library(tidyverse)
library(htmltools)
library(shinythemes)
war <- readLines("war.txt")
war_corpus <- corpus(war)
sentences <- tokens(war_corpus,what="sentence")
make_sentences <- function(word) {
grep(word,sentences,value= TRUE)}
sentence_line <- function(word) {
grep(word,sentences,value= FALSE)}
ui<- shinyUI(fluidPage(
# Application title
mainPanel(
img(src='image.jpg', align = "right"),
br(),
br(),
br(),
fluidRow(
column(2,
h5(HTML("<strong>Enter a word.Click \"SEARCH\" </strong>")),
wellPanel(
textInput("inputString","Enter a word here",value=" "),
submitButton("Search"),
)),
column(5,
h4("Search Results"),
wellPanel(
tags$style("#mytext { white-space: pre-line; }"),
htmlOutput("mytext")
)),
column(5, offset = 1.5,
h6("Uploaded File"),
wellPanel(
htmlOutput("showfile"))
)
)
),#Mainpanel
)#fluidpage
)#shinyUi
server <- function(input, output, session) {
output$mytext <- renderUI({
res <- make_sentences(input$inputString)[1]
res1<- sentence_line(input$inputString)[1]
tagList(
tags$a(href=paste('#',res1,sep=""),res1),tags$div(res)
)
})
output$showfile <- renderText({
includeHTML("www/final_tokens.html")
})
}
As you can see in the screenshot, for the word 'good' i am getting only the first sentence while actually I should be getting all sentences with word 'good' from txt file.(27 sentences in this case)