mastering-shiny icon indicating copy to clipboard operation
mastering-shiny copied to clipboard

Shiny app as a package - static `www` folder

Open paulimer opened this issue 2 years ago • 4 comments

Hi, I have followed closely the Package chapter, which has been of great help in our app development. However, I think this structure somehow drops the automatic link to thewww directory? Images are broken, connections can't be open, even though before switching to this structure it was all working.

I have found a temporary solution in adding addResourcePath(prefix = "www", directoryPath = "www"). But it seems to mess testing somewhat, as I get a

Error in `value[[3L]](cond)`: Couldn't normalize path in `addResourcePath`, with arguments: `prefix` = 'www'; `directoryPath` = './www'

while testing parts of the app with shinytest2.

paulimer avatar Apr 26 '22 13:04 paulimer

@paulimer Did you find a good resource explaining best practice for organising the folders? I face the same issue.

rjscherrer avatar Jul 02 '22 22:07 rjscherrer

After looking around a bit, I finally settled on an app inside the inst/app directory. Here a couple people suggested their own, in the end I used Chris Brownlie's as a template for mine. The key thing is to have ui and server functions defined in the R directory, and exported, then the inst/app/app.R can look like that:

if (isTRUE(getOption("shiny.testmode"))) pkgload::load_all("path/to/app") #for instance "../..", or better : rprojroot::is_r_package$find_file(), which return the project root
shiny::shinyApp(
  ui = your_package_name::your_package_ui()
  server = your_package_name::your_package_server()
)

paulimer avatar Jul 04 '22 11:07 paulimer

Great, thank you @paulimer!

rjscherrer avatar Jul 10 '22 13:07 rjscherrer

Here you can find a related GitHub issue.

ismirsehregal avatar Dec 01 '22 12:12 ismirsehregal