RShiny:如何将滑块居中

时间:2019-12-07 20:05:31

标签: r shiny shinydashboard shiny-server shinyjs

我是RShiny的新手,我正在尝试复制此模板:https://shiny.rstudio.com/gallery/retirement-simulation.html 我确实有此模板的代码,但这是一个学习练习。

这是我到目前为止所拥有的:

ui <- fluidPage(

  # Title goes here...
  titlePanel("Retirement: simulating wealth with random returns, inflation and withdrawals"),
  p("Description here..."),
  hr(),

  # Sidebar layout...
  sidebarLayout(
    # Sidebar panel...
    sidebarPanel(
      # Input: Slider for the number of observations to generate ----
      sliderInput("n",
                  "Param 1",
                  value = 500,
                  min = 1,
                  max = 1000),
      sliderInput("n",
                  "Param 2",
                  value = 500,
                  min = 1,
                  max = 1000),
      sliderInput("n",
                  "Param 3",
                  value = 500,
                  min = 1,
                  max = 1000),
      sliderInput("n",
                  "Param 4",
                  value = 500,
                  min = 1,
                  max = 1000)
    ),

    # Main panel...
    mainPanel(
      # Outputs of any plots...
      tabsetPanel(type = "tabs",
                  tabPanel("Plot", plotOutput("plot"))
      )
    )
  )
)

看起来不错,但我需要像上面的模板一样将滑块居中。非常感谢朝着正确方向的指针!

谢谢

Joesph

2 个答案:

答案 0 :(得分:0)

您可以结合使用wellPanel,fluidRow和column。

第一个fluidRow是将2个WellPanel并排保持50%的比例。在每个wellPanel中,我们使用fluidRows定义一行,然后使用宽度为6的2列定义2个宽度为50%的列。

ui <- navbarPage("Test",

     tabPanel("Data",

              fluidRow(column(
                6,
                wellPanel(
                  fluidRow(column(
                    6, sliderInput("input1", "input1", 0, 100, 5)
                  ),
                  column(
                    6, sliderInput("input2", "input2", 0, 100, 5)
                  )),

                  fluidRow(column(
                    6, sliderInput("input1", "input3", 0, 100, 5)
                  ),
                  column(
                    6, sliderInput("input3", "input4", 0, 100, 5)
                  )),

                  fluidRow(column(
                    6, sliderInput("input1", "input5", 0, 100, 5)
                  ),
                  column(
                    6, sliderInput("input2", "input6", 0, 100, 5)
                  ))
                )
              ))))

最终输出如下所示

enter image description here

答案 1 :(得分:0)

使用margin: auto CSS规则:

div(style = "margin: auto; width: 80%", # this number can be any percentage you need
    sliderInput(
                ...
                width = "100%" # this number has to be "100%", nothing less
               )
   )