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

Content not updated if collapsed = TRUE in Box #19

Closed
statnmap opened this issue Jan 16, 2019 · 2 comments
Closed

Content not updated if collapsed = TRUE in Box #19

statnmap opened this issue Jan 16, 2019 · 2 comments

Comments

@statnmap
Copy link
Contributor

Hi,
Thanks for putting bootstrap 4 available for Shiny applications.
I am running the github version. I face a problem with collapsed box.
When I uncollapse the box, the content does not appear. I will try to explore this but if you have an idea and/or a fix, that would be nice.
Below is a reproducible example:

library(shiny)
library(bs4Dash)
ui_test <- function() {
  bs4DashPage(
    title = "Test",
    sidebar = bs4DashSidebar(),
    navbar = bs4DashNavbar(),
    body = bs4DashBody(
      fluidRow(
        bs4Card(
          title = "Closable card with dropdown",
          closable = TRUE,
          width = 6,
          status = "warning",
          solidHeader = FALSE,
          collapsible = TRUE,
          labelText = 1,
          labelStatus = "danger",
          labelTooltip = "Hi Bro!",
          dropdownIcon = "wrench",
          dropdownMenu = dropdownItemList(
            dropdownItem(url = "https://www.google.com", name = "Link to google"),
            dropdownItem(url = "#", name = "item 2"),
            dropdownDivider(),
            dropdownItem(url = "#", name = "item 3")
          ),
          plotOutput("plot")
        ),
        bs4Card(
          title = "Closable card with gradient",
          closable = TRUE,
          width = 6,
          status = "warning",
          solidHeader = FALSE,
          gradientColor = "success",
          collapsible = TRUE,
          collapsed = TRUE,
          plotOutput("distPlot")
        )
      )
    )
  )
}

server_test <- function(input, output,session) {
  output$plot <- renderPlot({hist(cars[,1])})
  output$distPlot <- renderPlot({hist(cars[,2], col = "blue")})
}

shinyApp(ui_test(), server_test)
@DivadNojnarg
Copy link
Member

This is what I get from the shiny trace:

Listening on http://127.0.0.1:3013
SEND {"config":{"workerId":"","sessionId":"eba824b9842bfd3e1daf2b8c11a99b50","user":null}}
RECV {"method":"init","data":{".clientdata_output_plot_width":788,".clientdata_output_plot_height":400,".clientdata_output_plot_hidden":false,".clientdata_output_distPlot_hidden":true,".clientdata_pixelratio":1,".clientdata_url_protocol":"http:",".clientdata_url_hostname":"127.0.0.1",".clientdata_url_port":"3013",".clientdata_url_pathname":"/",".clientdata_url_search":"",".clientdata_url_hash_initial":"",".clientdata_url_hash":"",".clientdata_singletons":"7874ab6bc8e88ce841e7bc770d9fcdcd0e0032e3",".clientdata_allowDataUriScheme":true}}
SEND {"busy":"busy"}
SEND {"recalculating":{"name":"plot","status":"recalculating"}}
SEND {"recalculating":{"name":"plot","status":"recalculated"}}
SEND {"busy":"idle"}
SEND {"errors":[],"values":{"plot":{"src":"data:image/png;[base64 data]","width":788,"height":400,"coordmap":{"panels":[{"domain":{"left":-1,"right":26,"bottom":-0.68,"top":17.68},"range":{"left":59.04,"right":757.76,"bottom":325.56,"top":58.04},"log":{"x":null,"y":null},"mapping":{}}],"dims":{"width":788,"height":400}}}},"inputMessages":[]}

As you can see, the distPlot is hidden even when the collapse button is clicked. This mean that I need to create a jQuery event that will make the card content show when collapse is pressed, and inversely.

This is what happens between tabs in the sidebar and in the body: without jQuery nothing is displayed. See below (in shinydashboard.js):

// When document is ready, if there is a sidebar menu with no activated tabs,
// activate the one specified by `data-start-selected`, or if that's not
// present, the first one.
var ensureActivatedTab = function() {
  var $tablinks = $(".sidebar-menu a[data-toggle='tab']");

  // If there's a `data-start-selected` attribute and we can find a tab with
  // that name, activate it.
  var $startTab = $tablinks.filter("[data-start-selected='1']");
  if ($startTab.length === 0) {
    // If no tab starts selected, use the first one, if present
    $startTab = $tablinks.first();
  }

  // If there are no tabs, $startTab.length will be 0.
  if ($startTab.length !== 0) {
    $startTab.tab("show");

    // This is indirectly setting the value of the Shiny input by setting
    // an attribute on the html element it is bound to. We cannot use the
    // inputBinding's setValue() method here because this is called too
    // early (before Shiny has fully initialized)
    $(".sidebarMenuSelectedTabItem").attr("data-value",
      $startTab.attr("data-value"));
  }
};

If no tab is selected by the user, the first one is selected. They also add the "show" even to the related tab so that the content is displayed.

By the way, I need to see in the bootstrap 4 documentation what is available for card since it is different from a tab.

@DivadNojnarg
Copy link
Member

I also fixed the icon: + then the card is collapsed and - when it is uncollapsed

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