Use box in shiny folder structure. #331
-
I have a shiny app and this is my folder structure.
Where ui.R looks like
and
In
and when I click on Run App in Rstudio I get
This is the first time I am trying to use My questions are -
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi Ronak, That error isn’t actually related to ‘box’, it’s just a typo: you are calling the shinyApp(ui$ui, server$server) But there are some ‘box’ related code issues as well. In fact, some things might happen to work but aren’t guaranteed to work, and I strongly suggest changing them to make the code more robust. First off, inside the server you are using the wrong path in out <- readRDS(box::file("../Data/data.rds")) Secondly, you are currently importing relative modules via the paths To use submodules inside a project, I strongly recommend using relative module path specifications. To do this, prefix the paths with box::use(./code/ui,
./code/server,
shiny[shinyApp]) And personally I prefer aligning the module specifications: box::use(
./code/ui,
./code/server,
shiny[shinyApp],
) Also, make sure the capitalisation of the folder names matches, otherwise the code might work on Windows but will fail on other systems (your directory tree uses |
Beta Was this translation helpful? Give feedback.
Hi Ronak,
That error isn’t actually related to ‘box’, it’s just a typo: you are calling the
server$server
function instead of passing it toshinyApp
. Do the following instead:But there are some ‘box’ related code issues as well. In fact, some things might happen to work but aren’t guaranteed to work, and I strongly suggest changing them to make the code more robust.
First off, inside the server you are using the wrong path in
readRDS()
. You need to specify the path relative to the current module, because otherwise you are relying on the value ofgetwd()
, which isn’t generally robust. Usebox::file()
to get a guaranteed robust path: