0

When I build, load and run my own package, it is only using shinyBS functionalities if i beforehand load shinyBS with 'library(shinyBS)' otherwise tooltips are not working.. and although the shiny app works (whithout shinyBS features) there are webpage errors that can be seen through the browser console.. (about some missing files..shinyBS.css and shinyBS.js)

So the questions is: How can i generate, deploy and run my own shiny package without forcing the user to load shinyBS beforehand (doing 'library(shinyBS)' ) ?!

Thank you!

tanovsky
  • 73
  • 5
  • 1
    Your package should "import" the package, both by including it in `DESCRIPTION` as `Imports: shinyBS`, and including it in `NAMESPACE` with `import(shinyBS)` or `importFrom(shinyBS,functionname)` for each function you use. Then in your package code, you should use the double-colon notation, e.g., `shinyBS::bsModal` instead of just `bsModal`. Both the book and website are good references: http://r-pkgs.had.co.nz/ – r2evans Oct 04 '18 at 14:31
  • Alternative: use `Suggests: shinyBS` and include a condition of `if (require("shinyBS")) use_shinybs <- TRUE` at the start of each shiny app. From there, do `if (use_shinybs) shinyBS::bsModal(...)`, etc. Use this only if using it is *nice* but not *required*. (For this, do not include it in `NAMESPACE`.) – r2evans Oct 04 '18 at 14:53

2 Answers2

5

The usual way of adding dependencies to an R package is to add the packages in the Imports Field of the DESCRIPTION file. Here is an adaped version from Hadley Wickam's introduction.

Package: mypackage
Title: What The Package Does (one line, title case required)
Version: 0.1
Authors@R: person("First", "Last", email = "first.last@example.com",
                  role = c("aut", "cre"))
Description: What the package does (one paragraph)
Depends: R (>= 3.1.0), shiny
Imports: shinyBS
License: What license is it under?
LazyData: true

Then you will need to specify which functions from the shinyBS package are actually needed in the package with importsFrom in the NAMESPACE file. Alternatively, you can also import all shinyBS functions with

import(shinyBS)

However, in the case of shinyBS, you will actually need to put the dependency in the Depends field because of the way the onLoad/onAttach hooks are defined for that package. For more dertails, see here. Your DESCRIPTION file should therefore look like the following example

Package: mypackage
Title: What The Package Does (one line, title case required)
Version: 0.1
Authors@R: person("First", "Last", email = "first.last@example.com",
                  role = c("aut", "cre"))
Description: What the package does (one paragraph)
Depends: R (>= 3.1.0), shiny, shinyBS
License: What license is it under?
LazyData: true

This is quite unusual and in my opinion, this issue should be fixed from the shinyBS developers. However, in the mean time using the Depends field to make sure shinyBS is attached is a viable workaround for the issue you described.

Gregor de Cillia
  • 7,397
  • 1
  • 26
  • 43
1

You should use NAMESPACE to declare that you need shinyBS loaded in your package.

For example in your NAMESPACE file you should do:

import(shinyBS)

Furthermore, as noticed by @r2evans, you should add shinyBS in the Imports part of your DESCRIPTION file:

Imports: shinyBS

For more information check the R package website from Hadley Wickam: http://r-pkgs.had.co.nz/namespace.html#imports.

Thomas
  • 1,164
  • 13
  • 41
  • 1
    You need it in `DESCRIPTION`, too; without it, and there is no assurance that the package will be installed when this package is installed. (And it's `shinyBS`, for the record :-) – r2evans Oct 04 '18 at 14:35
  • 1
    Actually, `shinyBS` needs to be in the `Depends` field. Otherwise, certain JavaScript resources are not loaded properly. See [here](https://github.com/ebailey78/shinyBS/issues/100) – Gregor de Cillia Oct 05 '18 at 15:43