I created a fairly straight forward pdfsearch
search option with Shiny . However I want the output to be in the form of table for easy readability. I tried using Data Table package , but do not seem to get the right format I need or haven't figured out how exactly to use DT with dynamic text inputs
library(pdfsearch)
library(shiny)
library(DT)
file <- system.file('pdf', 'rhyme.pdf', package = 'pdfsearch')
word_sentence <-function(word) {keyword_search(file,
keyword = word,
path = TRUE)}
retobj <- function(word) {
x <- word_sentence(word)
page <- x$page_num
line <- x$line_num
text <- x$line_text
return(paste0(text," "," *Page no-",page," *line-",line))
}
ui<- shinyUI(fluidPage(dashboardBody(
img(src='image.jpg', align = "left"),style = "padding-top:20px",
br(),
br(),
br(),
br(),
fluidRow(
column(width = 2,
h5(HTML("<strong>Enter a word.Click \"SEARCH\" </strong>")),
wellPanel(
textInput("inputString","Enter a word here",value=" "),
submitButton("SEARCH"),
)),
column(width= 7,style = "max-height: 90vh; overflow-y: auto;",
h4("Search Results"),
wellPanel(
tags$style("#mytext { white-space: pre-line; }"),
textOutput("mytext")
))
)
)
)
)
server <- function(input, output, session) {
output$mytext <- renderPrint({
sentences <- retobj(input$inputString)
length(sentences)
cat(paste0(1:length(sentences)," - ",sentences,sep= '\n'))
})
}
shinyApp(ui,server)
I am now getting the output when i search the word 'hill' for eg. as :
1.jack went to the hill blah blah *Page no- 12 * line no -34
2.jack went rolling on hill blah *Page no 17 *line no - 56
3.jill climbed the hill blah blah * Page no 34 * line no -89
''''
20......
I would like the output to be in table format displayed in Shiny such as :
Text Page no Line No
jack went to the hill blah 12 34
jack went rolling on hill blah 17 56
jill climbed the hill blah 34 89
' ''''''''''
using renderDataTable
in server
part and tableOutput
in ui
of Shiny gives me output in R console instead of Shiny and I tried
retob <- function({.....tableHTML(text,page,line)}
but it was giving me error as says not matrix format.Is there a cleaner way to just format the content in the above mentioned way ?