Reputation: 3260
I am new to R shiny, and got some issues regarding loading data.
In my server.R
, I have some code to source R utility functions and R data. I put the data files in a subdirectory data
under the shiny app.
source("utilities.R")
load("data/mydata.RData")
The structure of my shinyServer
looks like following:
shinyServer(function(input, output, session) {
## ...
## I have a action Button, Run, to start model fitting
main_plot <- eventReactive(input$run, {
fit <- main.shiny()
post_analysis_shiny(fit = fit)
})
main.shiny <- function() {
## get input, fit model
## main.fit() is a function in utilities.R, which requires data saved in mydata.RData
fit <- main.fit()
fit
}
})
When I Run App, shiny cannot find the data. But if I manually load the data before I run shiny, everything works fine. What is the problem here? Thank you very much.
Upvotes: 2
Views: 2121
Reputation: 467
I suppose you are using Rstudio.
When you load and source "manually" in you R Rstudio session, data and functions are avaialble to shiny.
Otherwise to add on Jimbou answer : You should have in your shiny folder :
shinyappp
--- global.R
--- ui.R
--- server.R
--- utilisties.R
--- data
In global.R : you have :
source("utilities.R")
load("data/mydata.RData")
Upvotes: 3