ebailey78 / shinyBS

Twitter Bootstrap Components for Shiny
182 stars 47 forks source link

Move shiny::addResourcePath to .onLoad() #100

Open riccardoporreca opened 6 years ago

riccardoporreca commented 6 years ago

shinyBS resource publishing via shiny::addResourcePath is only performed .onAttach() and not .onLoad() https://github.com/ebailey78/shinyBS/blob/c329f8ce43e44579cafbb16fc3109fb69d403e57/R/misc.R#L1-L6

This can cause problems for Shiny apps which do not load attach shinyBS but only load its namespace (e.g., apps shipped as part of packages, with strict control over dependencies).

See related issues #92 and metrumresearchgroup/ggedit#17 and comments therein.

IvoryC commented 3 years ago

I converted my shiny app into an R package and I was SO confused about why my tips and popovers stopped working. And I really liked all my tips and popovers!

Calling library(shinyBS) would fix it...but then my package check command didn't pass. : ( And I shouldn't need that, I used shinyBS:: in front of all my calls to shinyBS functions.

Chipping at it, I found that adding this line to my server function brought the functionality back: shiny::addResourcePath("sbs", system.file("www", package="shinyBS"))} Yay! : )

The .onLoad() solution sounds reasonable to me, but I don't know all of the consequences of using .onAttach() vs .onLoad(); so I can't say if that is the best solution. What I CAN say is: please count my experience as an up-vote of the fact that there is a real problem in the current setup.

If for some reason you don't like the .onLoad() approach, something like a shinyBS::useShinyBS() call might work. That would be analogous to the shinyFeedback::useShinyFeedback() or shinyjs::useShinyjs() lines required by other packages.