Shiny app as a package - directory structure and www folder

In Chapter 20 of Mastering Shiny, there is the very good idea to organise a large and long term Shiny app as a package. It has simplified my code (no more source()) and simplified my workflow. My directory structure now resembles this :

├── data
├── R
└── www

However, I run into the issue of not knowing how to organise properly my static resources (videos, pictures..). A shinyApp() call inside the R directory does not seem to be able to give access to the www directory in the parent folder, so all the src = "img.png" do not work, and other includeMarkdown("text.md") create connection errors (cannot open the connection). The paths to data do work, on the other hand.
Has anyone found a solution to this?

I would try runApp()

It is not really a possibility, because using the package structure requires a function that starts the app I think. And runApp() does not return anything.

I think I see your issues, Mastering Shiny doesnt mention www folder or resource path anywhere that I can see, which does seem an oversight and might make sense to raise as an issue on their github.
I havent tried shiny as package so not aware of the issues or how to deal.
Perhaps look into golem for either direct use, or to see how they approach the resource path issue.
Also maybe someone here on the forum will have experience and will know how to advise you.

Yes I'm thinking about posting an issue there indeed. But the github does not seem very active.
But I feel like the documentation of shiny itself is a bit lacking on the subject. What is the difference between shinyApp() and runApp() apart from the return? Why is what I'm doing not working?
I'll look into golem if I don't manage to fix this some other way indeed! It looks somewhat difficult to adapt a sizeable project to it.
Thanks a lot for your answers !

Hi @paulimer,

I am not using golem but like @nirgrahamuk I think it can be a solution

Otherwise, you can have a look at the structure of my IFCshiny app which is organized as a package.

HTH

Below is how I structure my packages containing shiny apps:

├── R/
├── inst/
       ├── app/
            ├── global.R
            ├── server.R
            ├── ui.R
            ├── www/

I then have a function called run_app() or similiar, the definition of which is along the lines of:

run_app <- function() {
     runApp(appDir = system.file("app", package = "myPackage"))
}

E.g. GitHub - chrisbrownlie/advancedShiny: R package containing an R Shiny application which showcases some intermediate & advanced shiny methods

Thanks a lot for your answers and examples @cnbrownlie and @gitdemont ! I have many things to try then.

I also found a way to circumvent the issue, but if feels a bit hacky, I added this line : addResourcePath(prefix = "www", directoryPath = "./www"), but it does not work for every resource I think.This seems to work in Chromium for all the resources, but not really in Firefox for videos (I posted an issue about it, the behavior is weird). Edit : this seems unrelated.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.