Python, R, Shiny and Google APIs

A client wanted an easy way to quickly view upcoming event lists for any of their G Suite domain’s Google Resource Calendars. I tried keeping the solution entirely within R by using the googleAuthR package but domain-wide delegated authentication didn’t work properly for me so I reverted to Python. Without too much anguish I wrote a working parameterized script that returns Google resource calendar event details based on resource calendar ID and event count script arguments. Google provides helpful calendar API documentation and a basic reference example here

In RStudio Shiny, I capture the Python script arguments from Shiny UI user inputs, call the Python script with those argument parameters, return and parse the results then display those results in a dynamic data table. Here is the key Shiny portion:

# Create Google Calendar Python API script args from user inputs
 gcalEmailP <- reactive({
		gcalList <- input$showCalDrop
		if (is.null(gcalList))
 calEmailMatch <-
 gcalEventCountP <- reactive({
		gcalCt <- input$gcaleventcount
		if (is.null(gcalCt))
 gcalCt <- input$gcaleventcount

 # Call the Google Calendar API Python script with the params created above
 # only when the actionButton is clicked
	 gcalPythonScriptCall <- eventReactive(input$goCalButton,{    
		command <- "python.exe"
 # (Single and double quotes in the string needed if paths have spaces)
		path2script <- "c:/Projects/Python/"
		gaddress <- gcalEmailP()
		mtgcount <- gcalEventCountP()
		args <- paste0(" --gaddress ",gaddress, " --mtgcount ",mtgcount)
 # Add path to script as first arg
		allArgs <- c(path2script, args)
		output <- system2(command, args=allArgs, stdout=TRUE)
 # Parse the output into a dataframe for use in the data table
		output <- string.break.line(output)
		output <-
		names(output) <- c("allresults")
		output <- separate(output, allresults,
		          into = c("DateTime", "Event", "Organizer", "Creator"), 
		          sep = ",", remove = TRUE, extra = "drop")