mastering-shiny
mastering-shiny copied to clipboard
Shiny app as a package - static `www` folder
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 Did you find a good resource explaining best practice for organising the folders? I face the same issue.
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()
)
Great, thank you @paulimer!
Here you can find a related GitHub issue.