user51462
user51462

Reputation: 2022

R Shiny - Adding a 'remove' button to the box header

I am trying to add a title and remove button in the header of the box below:

enter image description here

Here is the code to reproduce the box:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    tags$style(HTML("

                  .my_class .box.box-solid.box-primary>.box-header {
                    background:rgba(0,128,128,.5);
                    height: 30px;
                    padding-top: 0px
                  }

                    .learner-title {margin-top:5px}

                    .box.box-solid.box-primary{
                    border-color:rgb(0,128,128);
                    background:rgba(0,128,128,.1)
                    }

                    ")),
    fluidRow(
      tags$div(class = "my_class", 
               box(width = 6, title = div(h4(class = "learner-title", "Box Title"), 
                                          div(class = "box-tools pull-right",
                                              tags$button(class = paste0("btn btn-box-tool"),
                                                          `data-widget` = "remove",
                                                          shiny::icon("remove")
                                                          ))
                                          ), status = "primary", solidHeader = TRUE,
                   "Box content"
                   )
               )
    )
  )
)


server <- function(input, output) {}

shinyApp(ui, server)

While the remove button works, I would like it to sit in the top-right corner of the box and slightly higher up in the header. In the code above, I tried to achieve the right alignment using class = "box-tools pull-right", but this doesn't seem to work.

Upvotes: 2

Views: 752

Answers (1)

DeanAttali
DeanAttali

Reputation: 26313

Try adding this CSS for the button

.box-tools.pull-right {
  position: absolute;
  right: 0;
  top: 0;
}

The .box-tools.pull-right selector is not the best, it would be better if you gave the button some more unique ID/class and used that instead as the identifier. But regardless, these CSS rules should do the trick.

Upvotes: 2

Related Questions