RinteRface / shinydashboardPlus

extensions for shinydashboard
https://shinydashboardplus.rinterface.com
Other
449 stars 78 forks source link

boxPlus sidebar_width is overwritten by last set. #85

Closed ajfisher83 closed 3 years ago

ajfisher83 commented 3 years ago

Hi,

I have found an issue were the last width set for the side bar overwrites all previous one.

For example:


   library(shiny)
   library(shinydashboard)
   library(shinydashboardPlus)

   header <- dashboardHeaderPlus(title = "Old Faithful Geyser Data")

   sidebar <-  dashboardSidebar()

   body <- dashboardBody(        

        boxPlus(
          title = "Number of Bins",
          width = 6,
          enable_sidebar= TRUE,
          sidebar_width = 80,
          sidebar_icon = "question-circle",
          sidebar_content = tagList(
            p("Move the slider to the right to increase the number of bins. Move the slider to the left to decrease the number of bins.")
          ),
          column(width = 12,
            sliderInput("bins",
                      "Number of bins:",
                      min = 1,
                      max = 50,
                      value = 30)
          )),

        boxPlus(width = 6,
          title = "Time Between Eruptions of Old Faithful",
          enable_sidebar= TRUE,
          sidebar_width = 40,
          sidebar_icon = "question-circle",
          sidebar_content = tagList(
            p("This histogram shows the frequency of times between eruptions of the Old Faithul Geyser.")
          ),
           plotOutput("distPlot")
        )
    )

# Define server logic required to draw a histogram
server <- function(input, output) {

    output$distPlot <- renderPlot({
        # generate bins based on input$bins from ui.R
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)

        # draw the histogram with the specified number of bins
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
    })
}

ui <- dashboardPagePlus(
  header,
  sidebar,
  body
)

# Run the application 
shinyApp(ui = ui, server = server)

Gives

image

I have found a work around using css and id tags like so:

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)

header <- dashboardHeaderPlus(title = "Old Faithful Geyser Data")

sidebar <-  dashboardSidebar()

body <- dashboardBody(        

        tags$head(tags$style(HTML('

              .direct-chat-contacts-open #slider_box  .direct-chat-contacts {
                      -webkit-transform: translate(20%, 0);
                      -ms-transform: translate(20%, 0);
                      -o-transform: translate(20%, 0);
                      transform: translate(20%, 0);
                }'))),

        boxPlus(
          id = "slider_box",
          title = "Number of Bins",
          width = 6,
          enable_sidebar= TRUE,
          sidebar_width = 80,
          sidebar_icon = "question-circle",
          sidebar_content = tagList(
            p("Move the slider to the right to increase the number of bins. Move the slider to the left to decrease the number of bins.")
          ),
          column(width = 12,
            sliderInput("bins",
                      "Number of bins:",
                      min = 1,
                      max = 50,
                      value = 30)
          )),

        boxPlus(
          id = "histogram_box",
          width = 6,
          title = "Time Between Eruptions of Old Faithful",
          enable_sidebar= TRUE,
          sidebar_width = 40,
          sidebar_icon = "question-circle",
          sidebar_content = tagList(
            p("This histogram shows the frequency of times between eruptions of the Old Faithul Geyser.")
          ),
           plotOutput("distPlot")
        )
    )

# Define server logic required to draw a histogram
server <- function(input, output) {

    output$distPlot <- renderPlot({
        # generate bins based on input$bins from ui.R
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)

        # draw the histogram with the specified number of bins
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
    })
}

ui <- dashboardPagePlus(
  header,
  sidebar,
  body
)

# Run the application 
shinyApp(ui = ui, server = server)

This then gives the expected result: image

It appear the boxes need an id tag so that the attributes can be set to them.

Cheers.

DivadNojnarg commented 3 years ago

wrong issue number sorry ...

DivadNojnarg commented 3 years ago

Fixed in latest devel