0

BACKGROUND

I'm building a shiny dashboard in Data Science Studio where a user has to choose a file they want to process from the selectizeInput and then press Submit actionButton. Once the button is pressed, it starts a backend process to determine what category the file falls into and what workflow it should follow (different workflows contain different cleaning steps and final outputs). Once the workflow completes, I want to display the final output in DT::renderDataTable.

DESIRED OUTPUT

I would like my shiny app to

  • show no data before the input is chosen
  • time, let's say, 30 seconds from the moment someone clicks the Submit button to actually picking up the dataset

MINIMAL WORKING EXAMPLE

How could I implement it in this simple app?

UI

library(shiny)
library(shinydashboard)
library(DT)
library(dataiku)

path <- dkuManagedFolderPath("receiver") #folder with the files to choose from


dashboardPage(
  dashboardHeader(title = "Catchy Title"),
  dashboardSidebar(


   selectizeInput("file", "Select File",
                list.files(path)), 

  actionButton("submit", "Submit")
  ),
  dashboardBody(
    fluidRow(

    box(h2("Show Data"),
        div(style = 'overflow-x: scroll', DT::dataTableOutput('mytable')),
          width = 12)
    )
  )
  )

SERVER

library(dataiku)
library(shiny)
library(shinydashboard)
library(DT)
library(dplyr)



shinyServer(function(input, output) {

file_name <- reactive({ 
req(input$file)
})

####
# run the process that takes the file name to pass it to 
# the global environment, which triggers the conditional workflow  
# and may result in different data outputs
####

## AFTER the process runs (approx. 30 seconds after pressing the submit button)
# I want the shiny app to follow this logic:

if(is.null(nrow(try(dkuReadDataset("intermediate_dataset"))[1]))){
    df <- dkuReadDataset("final_data1")
    } else{
    df <- dkuReadDataset("final_data2")
    }


output$mytable = DT::renderDataTable({
       df
    })  

})

Thanks for the hints!

Kasia Kulma
  • 1,683
  • 1
  • 14
  • 39
  • Check out this [answer](https://stackoverflow.com/a/38960525/3682794). – SeGa May 22 '18 at 11:52
  • I would advise against using a timer. Rather, make sure that your app updates whenever the process has finished running. For example, make the process write an RDS file with the result, and use a [reactiveFileReader](https://shiny.rstudio.com/reference/shiny/1.0.2/reactiveFileReader.html) to make your app dependent on changes to that file. – Florian May 22 '18 at 11:56
  • What about `delay()` from the [shinyjs](https://rdrr.io/cran/shinyjs/man/delay.html) package? – SeGa May 22 '18 at 12:01

0 Answers0