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

updateCollapse() doesn't work correctly without attaching shinyBS #92

Open
matdoering opened this issue Sep 7, 2017 · 1 comment
Open

Comments

@matdoering
Copy link

The documentation of shinyBS states that shinyBS should be attached after loading shiny in server.R/ui.R. However, for packages providing a shinyApp utilizing shinyBS it would be beneficial if attaching shinyBS wasn't a requirement. Indeed, when shinyBS it not attached, it seems that everything works fine except for updating bsCollapes.

Here's an example based on bsExample("Collapses"). Note that the collapses don't change when shinyBS is not loaded via library().

ui.R

#library(shiny)
#library(shinyBS)
shiny::fluidPage(
   shiny::sidebarLayout(
     shiny::sidebarPanel(shiny::HTML("This button will open Panel 1 using <code>updateCollapse</code>."),
                  shiny::actionButton("p1Button", "Push Me!"),
                  shiny::selectInput("styleSelect", "Select style for Panel 1",
                   c("default", "primary", "danger", "warning", "info", "success"))
     ),
     shiny::mainPanel(
       shinyBS::bsCollapse(id = "collapseExample", open = "Panel 2",
                  shinyBS::bsCollapsePanel("Panel 1", "This is a panel with just text ",
                   "and has the default style. You can change the style in ",
                   "the sidebar.", style = "info"),
                  shinyBS::bsCollapsePanel("Panel 2", "This panel has a generic plot. ",
                   "and a 'success' style.", shiny::plotOutput("genericPlot"), style = "success")
       )
     )
   )
) 

server.R

shiny::shinyServer(
 function(input, output, session) {
   output$genericPlot <- shiny::renderPlot(plot(rnorm(100)))
   shiny::observeEvent(input$p1Button, ({
     shinyBS::updateCollapse(session, "collapseExample", open = "Panel 1")
   }))
   shiny::observeEvent(input$styleSelect, ({
     shinyBS::updateCollapse(session, "collapseExample", style = list("Panel 1" = input$styleSelect))
   }))
 }
)
@GregorDeCillia
Copy link

GregorDeCillia commented Sep 16, 2017

I actually had similar issues and found a fix here. It seems the shinyBS resources are included with .onAttach rather than .onLoad (see source file).

My fix was to add the following lines somewhere in global.R or outside the app.

shiny::addResourcePath("sbs", system.file("www", package="shinyBS"))

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

2 participants