Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to use relative paths in global.R #197

Open
mszens opened this issue Feb 20, 2023 · 1 comment
Open

Need to use relative paths in global.R #197

mszens opened this issue Feb 20, 2023 · 1 comment

Comments

@mszens
Copy link

mszens commented Feb 20, 2023

Hi,
Radiant is great and we are trying to use it with a new set of data files and our use case requires us to set the file paths relative to getwd() - relative to the Project directory. We need these relative paths because we are pushing the mods we make to our local RStudio-Connect server using the rstudio publishing functions. If we don't we get this error:
"Line 6 Paths should be to files within the project directory."
Line 6 is : ifelse(grepl("radiant", getwd()) && file.exists("../../inst"), "..", system.file(package = "radiant")) %>%
options(radiant.path = .)

How do I configure the radiant paths in radiant/app/global.R so that they are relative to getwd()?
We tried this:

sourcing from radiant.data

options(radiant.path.data = system.file(package = "radiant.data"))

options(radiant.path.data = paste0(getwd(),"/radiant.data"))
source(file.path(getOption("radiant.path.data"), "app/global.R"), encoding = getOption("radiant.encoding", default = "UTF-8"), local = TRUE)

if (getOption("radiant.development", default = FALSE)) {

ifelse(grepl("radiant", getwd()) && file.exists("../../inst"), "..", system.file(package = "radiant")) %>%

ifelse(grepl("radiant", getwd()) && file.exists("../../inst"), "..", paste0(getwd(),"/radiant")) %>%
options(radiant.path = .)
}
...

But they we get the following:
Warning in file(filename, "r", encoding = encoding) :
cannot open file 'C:/Users/mszens/Documents/R-git/upstream_discov/radiant/app/radiant.data/app/global.R': No such file or directory ...

Is there a way to set the radiant paths to work within local project directories only?

Thanks so much,
Scot Zens

@vnijs
Copy link
Contributor

vnijs commented Feb 21, 2023

All shiny apps use the location of the R-code for the app as the current working directory. It has been some time since I set this up for Radiant and I haven't worked on an Rstudio/Posit Connect setup before.

Can you have the Connect run an application as an individual user? If so, then the settings below could be set in the users local .Rprofile file. It may also be possible to replace /Users/xyz with ~ but I can't test that at the moment.

Might be worth connecting with Rstudio/Posit as well if something like this isn't mentioned in their documentation.

If you find a set up that work, and I'm happy to connect about that more, then please do share the config information back with me so I can add it to the documentation

getOption("radiant.shinyFiles")
getOption("radiant.launch_dir")
getOption("radiant.sf_volumes")
getOption("radiant.shinyFiles")
[1] TRUE
getOption("radiant.launch_dir")
[1] "/Users/xyz/Dropbox/teaching/CustomerAnalytics/MGT455-2023"
getOption("radiant.sf_volumes") # needs a named list
MGT455-2023                                                                                                                
 "/Users/xyz/Dropbox/teaching/CustomerAnalytics/MGT455-2023"     
Home   
"/Users/xyz"
Desktop
"/Users/xyz/Desktop"                                                       
Dropbox                                                                                                    
"/Users/xyz/Dropbox" 
Google Drive     
"/Users/xyz/Library/CloudStorage/GoogleDrive-xyz"                                             

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants