简体   繁体   中英

Set bsButton position in shiny dashboard

I have a basic shiny dashboard below and I would like to know if I can a little bit left or right the bs button "show/hide sidebar".

#ui.r
library(shinydashboard)
library(shiny)
library(shinyBS)
dashboardPage(
  dashboardHeader(),
  dashboardSidebar(disable = TRUE),
  dashboardBody(
    tabsetPanel(
      id = 'testingDPEtab',
      tabPanel("Upload",
               bsButton("showpanel8", "Show/Hide sidebar",icon = icon("toggle-off"), type = "toggle",style = "info", value = TRUE),
               dashboardPage(
                 dashboardHeader(),
                 dashboardSidebar(),
                 dashboardBody())

    )
  )
))
#server.r
server <- function(input, output) { }

Depending on whether you want to apply the "moving" to a specific button or for all these buttons you can do:

tags$head(
  tags$style(HTML('#showpanel8{margin-left:10px}'))
)

Here, the button is referenced by id. So the change will only apply to that button. #showpanel8{margin-left:10px} is CSS syntax to style the button. For other margins you can use:

  • margin-top
  • margin-right
  • margin-bottom
  • margin-left

See here: https://www.w3schools.com/css/css_margin.asp .

Full reproducible example:

library(shinydashboard)
library(shiny)
library(shinyBS)
ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(disable = TRUE),
  dashboardBody(
    tags$head(
      tags$style(HTML('#showpanel8{margin-left:10px}'))
    ),
    tabsetPanel(
      id = 'testingDPEtab',
      tabPanel("Upload",
               bsButton("showpanel8", "Show/Hide sidebar",
                        icon = icon("toggle-off"), type = "toggle",
                        style = "info", value = TRUE),
               dashboardPage(
                 dashboardHeader(),
                 dashboardSidebar(),
                 dashboardBody())

      )
    )
))
#server.r
server <- function(input, output) { }

shinyApp(ui, server)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM