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

Shiny app as a package - static www folder #562

Open
paulimer opened this issue Apr 26, 2022 · 4 comments
Open

Shiny app as a package - static www folder #562

paulimer opened this issue Apr 26, 2022 · 4 comments

Comments

@paulimer
Copy link

paulimer commented Apr 26, 2022

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.

@rjscherrer
Copy link

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

@paulimer
Copy link
Author

paulimer commented Jul 4, 2022

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()
)

@rjscherrer
Copy link

Great, thank you @paulimer!

@ismirsehregal
Copy link

Here you can find a related GitHub issue.

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

3 participants