I am getting the output in R just like wanted however there is zero output in Shiny .Not able to figure out if function I wrote is wrong or my syntax in Shiny ?
search.txt content <- “Well, Prince, so Genoa and Lucca are now just family estates of the Buonapartes. But I warn you, if you don’t tell me that this means war, if you still try to defend the infamies and horrors perpetrated by that Antichrist—I really believe he is Antichrist—I will have nothing more to do with you and you are no longer my friend, no longer my ‘faithful slave,’ as you call yourself! But how do you do? I see I have frightened you—sit down and tell me all the news.”
It was in July, 1805, and the speaker was the well-known Anna Pávlovna Schérer, maid of honor and favorite of the Empress Márya Fëdorovna. With these words she greeted Prince Vasíli Kurágin, a man of high rank and importance, who was the first to arrive at her reception. Anna Pávlovna had had a cough for some days. She was, as she said, suffering from la grippe; grippe being then a new word in St. Petersburg, used only by the elite... " ('War n Peace' literature file)
R studio output i would need in Shiny
text14 "replied the prince, not in the least disconcerted by this reception."
text26 "I must put in an appearance there," said the prince."
text30 ""If they had known that you wished it, the entertainment would have been put off," said the prince, who, like a wound-up clock, by force of habit said things he did not even wish to be believed."
text35 "replied the prince in a cold, listless tone."
text68 ""I think," said the prince with a smile, "that if you had been sent instead of our dear Wintzingerode you would have captured the King of Prussia's consent by assault."
text78 ""I shall be delighted to meet them," said the prince."
text86 "The prince was silent and looked indifferent."
text91 "The prince bowed to signify his respect and gratitude."
library(quanteda)
library(shiny)
library(tm)
library(tidytext)
library(tidyverse)
search_file <- readLines("search.txt")
search_corpus <- corpus(search_file)
sentences <- tokens(search_corpus,what="sentence")
z <- grep("good",sentences,value=TRUE) #working example
head(z)
make_sentences <- function(word, n = 10, use.seed = FALSE) {
sapply(seq_len(n), function(i) {
if (use.seed) set.seed(i)
grep(word,sentences,value=TRUE)
})
}
make_sentences("prince ") # seems to be working here in Rstudio
ui<- shinyUI(fluidPage(
# Application title
mainPanel(
img(src='image.jpg', align = "right"),
fluidRow(HTML("<strong> Search Bar")),
fluidRow(
br(),
p("User Name : ")),
br(),
br(),
fluidRow(HTML("<strong>Enter a word.Click \"Next words\" after</strong>") ),
fluidRow( p("\n") ),
# Sidebar layout
sidebarLayout(
sidebarPanel(
textInput("inputString","Enter a word here",value = " "),
submitButton("Next words")
),
mainPanel(
h4("Are you looking for this ?"),
tags$style("#mytext {white-space: pre-line;}"),
verbatimTextOutput("link")
)
)
)))
server <- function(input, output, session) {
output$mytext <- renderPrint({
sentences <- rep(make_sentences(input$inputString))
length(sentences)
cat(paste0(1:length(sentences)," ",sentences,sep= '\n'))
})
}
shinyApp(ui,server)