Coder Social home page Coder Social logo

Comments (8)

mattflor avatar mattflor commented on August 20, 2024

I just found out that I have the same issue. This is currently a big show stopper for me, too. Have you ever found a way around this?

Here's a reproducible example I made by adapting the updateCollapse example (https://ebailey78.github.io/shinyBS/docs/Collapses.html#updateCollapse):

library(shiny)
library(shinyBS)

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(
            bsCollapse(
                id = "collapseExample", open = "Panel 2",
                bsCollapsePanel(
                    title = "Panel 1", 
                    style = "info",
                    p("This is a panel which has the default style. You can change the style in the sidebar."),
                    p("However, something goes wrong with this panel's shiny communication when there is a visible conditionalPanel inside of it. First, set", code("options(shiny.trace = TRUE)"), " and start the app. Open and close panels 1 and 2 and you'll see messages like this in the console:"), 
                    p(code("RECV {'method':'update','data':{'collapseExample':['Panel 1'],'.clientdata_output_genericPlot_hidden':true}}")),
                    p(code("RECV {'method':'update','data':{'collapseExample':['Panel 2'],'.clientdata_output_genericPlot_hidden':false}}")), 
                    p("Now choose the panel style 'danger' in the sidebar which will trigger the display of a conditionalPanel within panel 1. Then open and close panels 1 and 2 again and watch shiny's messages in the console:"), 
                    p(code("RECV {'method':'update','data':{'collapseExample':['Panel 1','Panel 2'],'.clientdata_output_genericPlot_hidden':false}}")),
                    p(code("RECV {'method':'update','data':{'collapseExample':['Panel 1','Panel 1'],'.clientdata_output_genericPlot_hidden':true}}")),
                    conditionalPanel(
                        condition = "input.styleSelect == 'danger'",
                        wellPanel(
                            h1("DANGER ZONE"),
                            p("'Panel 1' seems to be added to shiny's messages. This can mess up everything pretty bad if one uses a lot of conditional panels.")
                        )
                    )
                ),
                bsCollapsePanel(
                    title = "Panel 2", 
                    style = "success", 
                    "This panel has a generic plot. ",
                    "and a 'success' style.", 
                    plotOutput("genericPlot")
                )
            )
        )
    )),
    server = function(input, output, session) {
        output$genericPlot <- renderPlot(plot(rnorm(100)))

        observeEvent(input$p1Button, ({
            updateCollapse(session, "collapseExample", open = c("Panel 1"))
        }))

        observeEvent(input$styleSelect, ({
            updateCollapse(session, "collapseExample", 
                           style = list("Panel 1" = input$styleSelect))
        }))
    }
)

from shinybs.

 avatar commented on August 20, 2024

I did not find a workaround. I ended up not using this feature in my projects

from shinybs.

mattflor avatar mattflor commented on August 20, 2024

Damn it. Thanks anyway for the quick response!

from shinybs.

mattflor avatar mattflor commented on August 20, 2024

@pan0ramic Don't know whether you got notified automatically, but I just made a pull request with a fix for this issue. Hopefully, that is. Seems to work for my shiny app.

from shinybs.

trDC avatar trDC commented on August 20, 2024

+1 also having this issue.

from shinybs.

 avatar commented on August 20, 2024

@mattflor I didn't see this! Thanks for making the commit. Doesn't look like the author wants to merge though :(

from shinybs.

akaever avatar akaever commented on August 20, 2024

We have encountered the same issue (nested collapsePanels or conditionPanels within a collapsePanel). It seems that the nested elements fire the same event (show.bs.collapse and hide.bs.collapse). The provided fix did not solve the issue in our case. However, adding an explicit check whether the parent().parent() of the event.target is the actual bsCollapsePanel (and thereby avoiding nested events) did it:

$panels.on("show.bs.collapse", function(event) {
  // make sure this is not an event from a nested element
  if(!($el.is($(event.target).parent().parent()))) {
    return;
  }
  // ...
});

$panels.on("hide.bs.collapse", function(event) {
  // make sure this is not an event from a nested element
  if(!($el.is($(event.target).parent().parent()))) {
    return;
  }
  // ...
});

Perhaps there is a more elegant solution...

from shinybs.

natbprice avatar natbprice commented on August 20, 2024

I also encountered this bug. I proposed a workaround on Stackoverflow (https://stackoverflow.com/questions/58015021/conflict-between-shinybsbscollapse-and-shinyconditionalpanel) where shiny::conditionalPanel is replaced by the following:

uiOutput("condPanelA")
output$condPanelA <- renderUI({
  if(input$showPanelA) {
     helpText("Panel A conditional content")
  } else {
    NULL
  }
})

from shinybs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.