firmo23
firmo23

Reputation: 8404

Set button position in shinydashboard sidebar

I have a very basic shiny dashboard and I would like to set the position of this actionbutton exactly in the middle of the sidebar. It must have exactly the same distance from both sidebar sides.

app.R

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(
title="Select Data to View or Download",
      titleWidth = 335),
  dashboardSidebar(
width = 335,
actionButton("load","Apply Selections")),
  dashboardBody()
)

server <- function(input, output) { }

shinyApp(ui, server)

Upvotes: 1

Views: 2466

Answers (2)

Wilmar van Ommeren
Wilmar van Ommeren

Reputation: 7689

An easier approach (and centered without offset) is to set the button position with the style argument.

actionButton("load", "Apply Selections", style='margin:auto')

Upvotes: 3

Sada93
Sada93

Reputation: 2835

This can be done by putting it in a column and setting align = "center".

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(
    title="Select Data to View or Download",
    titleWidth = 335),
  dashboardSidebar(
    width = 335,
    column(12,align = "center",offset = 0,actionButton("load","Apply Selections"))),
  dashboardBody()
)

server <- function(input, output) { }

shinyApp(ui, server)

Upvotes: 1

Related Questions