[英]Load RData into Shiny - data loaded in R workspace but not in Shiny, no errors produced
Objective: I seek to download a data set (in .RData
format) I have uploaded on GitHub
to a Shiny
app, and use the data set for various plotting purposes. 目标:我寻求将已在GitHub
载的数据集( .RData
格式)下载到Shiny
应用程序,并将该数据集用于各种绘图目的。
Technique: I am using the source_data
function from the repmis
package to load the data into my R session. 技术:我正在使用repmis
包中的source_data
函数将数据加载到我的R会话中。 This loading occurs at the global.R
file, so I was certain any data loaded would be available to plotting functions in the server.R
file. 这种加载发生在global.R
文件中,因此我确定所加载的任何数据都可用于在server.R
文件中绘制函数。
Problem: I see the data is loaded in my R workspace if I shift all functions from global.R
to server.R
but just before the shinyServer()
function. 问题:如果我将所有函数从global.R
到server.R
但仅在shinyServer()
函数之前,我会在R工作区中加载数据。
However, no data is available to the Shiny
app, no error is produced, just that nothing is available to plot, or even inspect using dim()
. 但是, 没有数据是提供给Shiny
应用,产生没有错误,只是没有可供使用的绘制,甚至使用检查dim()
Similar Questions: There is a similar question here , but I haven't obtained any help from this - I am, anyway, loading data in Global.R
rather than in server.R
or ui.R
. 类似的问题:有一个类似的问题在这里 ,但我没有得到任何与此帮助-我,反正在加载数据Global.R
而不是server.R
或ui.R
。
Another question is here , but the user reads in data to a reactive source. 另一个问题在这里 ,但是用户将数据读入反应性源。 My data would not be changing, so I am loading it in the global.R
file. 我的数据不会更改,因此我将其加载到global.R
文件中。
#global.R
#-------------------- Loading Libraries ------------------------#
library(repmis)
library(lubridate)
library(dplyr)
library(xts)
library(dygraphs)
#-------------------- Loading required data from GitHub Repo -------------------------#
source_data('https://github.com/aliarsalankazmi/SHB_FB_App/raw/master/Data/shbPageData.RData')
#-------------------- Manipulating data for further processing -------------------------#
shb$created_date <- ymd(gsub('T.*', '', shb$created_time))
pageData <- tbl_df(shb) %>%
arrange(created_date)
byDay <- pageData %>%
group_by(created_date) %>%
select(created_date, comments_count, likes_count, shares_count) %>%
summarise(totalPosts = n(),
totalLikes = sum(likes_count),
totalComments = sum(comments_count),
totalShares = sum(shares_count)) %>%
arrange(created_date)
#-------------------- Manipulating data for an Overall View -------------------------#
byDayxts <- as.xts(x = as.matrix(as.data.frame(byDay[,colnames(byDay) != 'created_date'])), order.by = byDay$created_date)
#server.R
library(shiny)
library(dygraphs)
shinyServer(function(input, output, session) {
#---------------------- Plotting for a General Overview --------------------#
totalOverview <- renderDygraph({
byDayxts[, colnames(byDayxts) == 'totalPosts'] %>%
dygraph(main = 'Total Posts per Day Since Beginning', group = 'overall') %>%
dyAxis('x', drawGrid = FALSE) %>%
dySeries('totalPosts', label = 'Total Posts') %>%
dyOptions(includeZero = TRUE, gridLineColor = "lightblue", colors = '#d8b365') %>%
dyRangeSelector()
})
})
#ui.R
library(shiny)
library(dygraphs)
shinyUI(fluidPage(
titlePanel(h1("Facebook Data Analysis")),
tabsetPanel(
tabPanel("Graphs",
fluidRow(
column(width = 6, dygraphOutput("totalOverview"))
)
)
)
)
)
It should be: 它应该是:
output$totalOverview <- renderDygraph({ ... })
not: 不:
totalOverview <- renderDygraph({ ... })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.