Search code examples
shiny-server

Server Code for Shiny-Server for a Specific App is not showing any of the Dataframes


enter image description hereSo the ui.R file is working perfectly. However, the server.R is what I suspect may be causing the issue here. The intended behavior is that I have data frames display above the embedded HTML charts on each one of my pages. However, the data frames are not generated. The intended goal is to use the google sheets package, read a google sheet, and then morph it into a data frame exposed on R Shiny.

I have tried placing the data frame function and definition above and below within the ui.R and the server.R. However, I am not getting any return on any of the output.

This is for a Shiny-Server hosted on Ubuntu 16.04 Server.

#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
#    http://shiny.rstudio.com/
#

library(shiny)
library(shinydashboard)
library(googlesheets)
library(googleCharts)
library(googleAuthR)
library(stats)
library(searchConsoleR)
library(googleAnalyticsR)
library(httr)
library(dplyr)
library(plyr)
library(mosaic)
library(DT)
library(httpuv)
library(htmltools)

# Google Sheets for Synced Keys with Data Master
# ===============================================
handover <- gs_key("1Wu8gJ#$%%#$%%#@#$@@$#%@@#$%@#%-VVHcB8c")
for_gs_sheet <- gs_read(handover)
str(for_gs_sheet)

# Define server logic required to draw a histogram
shinyServer(function(input, output) {
  google_app <- oauth_app(
    "google",
    key = "3901########################m",
    secret = "b#########################z"
  )
  #oauth2.0_token(google_app)
    ## ---------- Google Authentication ---------- ##
    gs_auth(token = NULL ,new_user = FALSE,
            key = getOption("################.com"),
            secret = getOption("##############Ka5mz"),
            cache = getOption("googlesheets.httr_oauth_cache"), verbose = TRUE)

        for_gs_sheet <- gs_read(handover)
        str(for_gs_sheet)

    output$mytable = DT::renderDataTable({
        df <- gs_read(handover)
    })
})

enter image description here The actual results should show output as related to the DT package. However, the data table is not being processed and/or is not made visible when called in the server output.


Solution

  • This stems from a service token issue. The best way is to just create a service token and session that maintains an open connection and refreshes the token.

    I fixed this issue by backing the token directly into the app via JSON and having the app call the JSON file within the directory the shiny app was stored in under the /srv/ directory. You can download a copy of the service account information and store it in the working directory of the app:

    root@miradashboard1:/srv/shiny-server/Apps/CSM# ls
    miradashboard-f89f243d0221.json  server.R  ui.R
    

    Then make sure you call the service token within the server.R and ui.R.

    service_token <- gar_auth_service(json_file="/srv/shiny-server/Apps/CSM/miradashboard-f89f243d0221.json")