如何在 R Shiny 应用程序中对齐 downloadButton 和 ActionButton?

Viv*_*viG 2 r button shiny

我有一个 Shiny 应用程序,侧边栏上有两个按钮,但我无法对齐它们。我尝试了此处给出的解决方案(Shiny R 对齐按钮),但它对我不起作用。

这是它们的样子

这是一个可重现的代码:


library(shiny)
library(DBI)
library(shinydashboard)
library(DT)
library(shinyjs)


ui <- dashboardPage(
#Header 
  dashboardHeader(title = "Labware dashboard"),
#Sidebar with download button  
  dashboardSidebar(
    width = 130,
    downloadButton('downloadData',
                   'Download',
                   style = "color: #fff; background-color: #27ae60; border-color: #fff"),
#Create a button in the sidebar to stop app
    useShinyjs(),
    extendShinyjs(text = jscode, functions = ("closeWindow")),
    actionButton("close", "Close window", 
                icon("close"),
               style = "color: #fff; background-color: red; border-color: #fff")
  ),
  
  dashboardBody()
  
  )


server <- function(input, output, session) {
  

  #close the app
  observeEvent(input$close, {
    js$closeWindow()
    stopApp()
  })#   session$onSessionEnded(stopApp) 
}


shinyApp(ui, server)

Run Code Online (Sandbox Code Playgroud)

它看起来actionButton并且downloadButton没有相同的格式,因为如果我用另一个(两个相同按钮类型)替换一个,我会让它们对齐,但我不知道如何更改它们的位置。有任何想法吗?

Hub*_*rtL 7

这是因为它们没有相同的边距,但是您可以像这样修复 css:

downloadButton('downloadData',
               'Download',
               style = "color: #fff; background-color: #27ae60; border-color: #fff;padding: 5px 14px 5px 14px;margin: 5px 5px 5px 5px; ")

actionButton("close", "Close window" ,
             icon("close"),
             style = "color: #fff; background-color: red; border-color: #fff;width:130;padding: 5px 5px 5px 5px;margin: 5px 5px 5px 5px; ")
Run Code Online (Sandbox Code Playgroud)

应用程序