在Shinydashboard侧边栏中设置按钮位置

时间:2019-02-08 14:50:45

标签: r shiny shinydashboard

我有一个非常基本的闪亮仪表板,我想将此actionbutton的位置恰好设置在侧边栏的中间。它与侧边栏两侧的距离必须完全相同。

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)

2 个答案:

答案 0 :(得分:1)

一种更简单的方法(居中且无偏移)是使用style参数设置按钮位置。

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

答案 1 :(得分:0)

这可以通过将其放入column并设置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)