I am developing a shiny application to display words and images from a file one after another in the interval of 1 second on shiny UI. If a user selects a file, it read the file and display the 1st word on UI then after 1-second 1st word disappears and 2nd word displayed on UI and then again after 1-second 2nd word disappears and 3rd word displayed on UI and so on. If there is an image in the file then it should also display on UI.
I wrote a code to get a word from a sentence in each second of interval. Right now it is displayed on R console but I want to display these words and images in the shiny UI.
Below is an illustration of the problem (it's not my actual code for cleanliness reasons, but it works as an illustration):
library(shiny)
library(shinydashboard)
library(stringr)
ui <- dashboardPage(skin = 'purple',
dashboardHeader(title = "Document Reader"),
dashboardSidebar(width = 200,
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"))
)
),
dashboardBody(skin = 'purple',
tabItems(
# First tab content
tabItem(tabName = "dashboard",
h2("Dashboard tab content"),
fluidRow(
box(title = "Uploading File",
fileInput("text", "Enter Text:"),
actionButton(inputId = "submit",label = "Read")
),
column(8,uiOutput("opt1"))
)
)
)
)
)
server <- function(input, output, session) {
cat("\014")
input_file1 <- eventReactive(input$submit,{
filepath <- input$text$datapath
doc <- readLines(filepath)
words = unlist(strsplit(doc, ' '))
total = length(words)
for (w in 1:total){
len = length(words[[total]])
for (w1 in 1:len){
print(words[[w]][w1])
Sys.sleep(1)
cat("\014")
}
}
})
output$data_1 <- renderText({
fileText_1 <- input_file1()
return(fileText_1)
})
output$opt1 <- renderUI({
verbatimTextOutput("data_1")
})
}
shinyApp(ui, server)
How can I display these words on shiny UI?