简体   繁体   中英

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.

Technique: I am using the source_data function from the repmis package to load the data into my R session. 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.

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.
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() .

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 .
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

#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

#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({ ... })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM