特定应用程序的 Shiny-Server 服务器代码未显示任何数据帧

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

因此 ui.R 文件运行良好。但是,server.R 是我怀疑可能导致此处问题的原因。预期的行为是我在每个页面上的嵌入式 HTML 图表上方显示数据框。但是,不会生成数据帧。预期目标是使用 google sheets 包,读取 google sheet,然后将其变形为暴露在 R Shiny 上的数据框。

我尝试将数据框函数和定义放在 ui.R 和 server.R 的上方和下方。但是,我没有在任何输出上得到任何 return。

这适用于 Ubuntu 16.04 服务器上托管的 Shiny-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)
    })
})

实际结果应该显示与 DT 包相关的输出。但是,数据 table 未被处理 and/or 在服务器输出中调用时不可见。

这源于服务令牌问题。 最好的方法是只创建一个服务令牌和会话,以保持打开的连接并刷新令牌。

我通过 JSON 将令牌直接备份到应用程序并让应用程序调用 shiny 应用程序存储在 /srv/ 目录下的目录中的 JSON 文件来解决这个问题.您可以下载一份服务账号信息,存放在应用的工作目录中:

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

然后确保在 server.R 和 ui.R 内调用服务令牌。

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