简体   繁体   中英

How do I align downloadButton and ActionButton in R Shiny app?

I have a Shiny app that has two buttons on the sidebar, but I can't align them. I tried the solution given here ( Shiny R aligning buttons ), but it did not work for me.

Here is how they look like .

Here is a reproducible code:


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)

It looks like actionButton and downloadButton don't have the same formatting because if I replace one with another (two of the same button type) I get them aligned, but I have no idea on how to change their placement. Any ideas?

It's because they don't have same margins, but you can fix css like this:

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; ")

应用程序

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