Publishing shiny app along with file from other directory

I am trying to publish my shiny app to RStudioConnect. In my app.R I have sourced a file from a parent directory. Though it works fine on my local machine, when I try to publish the app:
a) I am unable to view the files in the pane where we select files to be published
b) If I proceed with publishing, I get the error-> Paths should be to files within the project directory.

Our aim was to have this file common to all our projects so that everyone can just source the same file instead of rewriting. But since the file is not in the same directory as app.R, it isn't being published.

Can anyone suggest a workaround or a better approach for reusing common files?

Hi @mohan_mishra,

RStudio Connect currently only supports deploying files in subdirectories of the deployment directories (not parents, as you've figured out). That said, this is a request we've heard before. There might be a workaround, depending on exactly what you're trying to do. Either way, we'd love to capture some details on what you're trying to do here if you wouldn't mind answering the questions below:

  • What are the files you're trying to deploy with RStudio Connect? Helper functions? Data? Components of an app?
  • Are you doing push-button deployment, deploying from git, or using another continuous integration strategy?
  • How are the apps you're trying to deploy related to each other?

Hey @alexkgold ,

  1. This file contains code to generate a UI Component for the app. We have made this generic enough so that different projects can use this file and generate the UI component within their apps. We also have certain files for helper functions such as connecting to DB

  2. We are doing push-button deployment

  3. It is one single app which I am trying to deploy. However this app has a component which can be reused by different app owners in their shiny dashboards

Hi @mohan_mishra,

That totally makes sense. Would the other shiny apps also be in child directories of the main one? So it'd look something like this:

  - helper_funcs.R
  - ui_component.R
  - app1/
    - app.R
  - app2/
    - app.R

In general, our recommendation for reusable code snippets would be to put them into an R package.

If the Shiny UI elements aren't already functions, you could turn those into modules.

RStudio Connect can automatically install packages from public git repos, just like from CRAN when your content is deployed. In this case, you'd probably need to store the package somewhere private. RStudio Package Manager supports watching a private git repo to make packages available to the IDE as well as RStudio Connect. If that's not an option, RStudio Connect does support installing private packages (See the bottom of the article).

Okay. So you suggest that instead of having the common thing as R file, we should convert it to a package?

Yes, generally the best way to share R code among multiple pieces of content is to put it into a package.

That said, we're also interested in improving the way code is shared among content on RStudio Connect and I'm recording this feedback internally. Thank you for sharing it!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.