1

I want to know the way to build a Shiny App which automatically runs functions in a scheduled time. I read this but it doesn't seem relevant to my case.

I created a function to update a google sheet, using the package googlesheet. Now the app ui looks like this.

enter image description here

Clicking "Manually update" button enables the app to run the functions and update the googlesheet.

But I want the app to run the same function everyday at 1pm, even without clicking "Manually update" button, while "Activate auto update" button is on.

So to summarise, I want to know

  1. the way to automatically execute the functions at a scheduled time in shiny app.
  2. the way to save the user input of "Activate auto update". That is to say, once you turn on this button, even if you close this app and open it again, it stays to be "on". Once you turn off this button, it stays to be "off" until the user turn it on again, even if the user shuts off the app.

I'd appreciate for any kinds of help!

ui.R

navbarPage("Automated Report Generator", id = "nav",

           tabPanel("ITM",
                    sidebarLayout(
                      sidebarPanel(materialSwitch(inputId = "activateAutoITM", 
                                                  label = "Activate auto update", 
                                                  status = "primary", right = FALSE),
                                   actionButton("ITM_update", "Manually update"),
                               width = 2),
                  mainPanel(div(a("Visit ITM Google Sheet",
                                  href = "https://docs.google.com/spreadsheets/d/#########",
                                  target="_blank")),
                            div(htmlOutput("gsheet_text_ITM"))
                ) 
                ) # sidebarLayout
            )) # navbarPage

server.R

shinyServer(function(input, output, session) {

  observeEvent(input$ITM_update, {

    ####### Here are the functions to update google sheet########
    ####### But I'll just omit because of the security#########

    output$gsheet_text_ITM <- renderUI({
          str1 <- paste("Calculation finised.")
          HTML(paste(str1))
    })
  }) # shinyServer
Makoto Miyazaki
  • 1,743
  • 2
  • 23
  • 39
  • Are you running this local on your computer or on a server. Any way you will have to look in to starting and stopping a cronjob whenever the button `activateAutoITM` is used – Bertil Baron Jun 25 '18 at 11:10
  • Thanks for your comment Bertil. I'm running this on a server in my company, which is accessible only via wifi in my office. I just subscribed to cronjob and created a new cron project, but it returns "This URL is banned. If you have questions, please contact info@cron-job.org.". Is this because of the access permission? Would you please give me an advice a bit more in detail? – Makoto Miyazaki Jun 25 '18 at 14:54

0 Answers0