including shinyBS in a package

513 Views Asked by At

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!

2

There are 2 best solutions below

0
On

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 = "[email protected]",
                  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 = "[email protected]",
                  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.

2
On

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.