ebailey78 / shinyBS

Twitter Bootstrap Components for Shiny
182 stars 47 forks source link

addResourcePath should be called .onLoad, not .onAttach #115

Open rfaelens opened 4 years ago

rfaelens commented 4 years ago

When using shinyBS using shinyBS::bsCollapsePanel, the javascript and CSS fails to load. This is because the shiny resourcePath is only registered .onAttach. It should be registered .onLoad instead.

Reprex (! load this in a clean R session without attaching the shinyBS library):

library(shiny)
shinyApp(
  ui =
    fluidPage(
      sidebarLayout(
        sidebarPanel(HTML("This button will open Panel 1 using updateCollapse."),
                     actionButton("p1Button", "Push Me!"),
                     selectInput("styleSelect", "Select style for Panel 1",
                                 c("default", "primary", "danger", "warning", "info", "success"))
        ),
        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.", plotOutput("genericPlot"), style = "success")
          )
        )
      )
    ),
  server =
    function(input, output, session) {
      output$genericPlot <- renderPlot(plot(rnorm(100)))
      observeEvent(input$p1Button, ({
        shinyBS::updateCollapse(session, "collapseExample", open = "Panel 1")
      }))
      observeEvent(input$styleSelect, ({
        shinyBS::updateCollapse(session, "collapseExample", style = list("Panel 1" = input$styleSelect))
      }))
    }
)
rfaelens commented 4 years ago

https://github.com/ebailey78/shinyBS/pull/116 : pull request to fix this