【问题标题】:R Shiny - Vertically aligning a label and input in a horizontal formR Shiny - 垂直对齐标签并以水平形式输入
【发布时间】:2019-05-06 02:04:03
【问题描述】:

我正在尝试以水平形式垂直对齐输入及其标签。我不确定是否可以垂直对齐不同高度的内联 div。

下面的代码给了我以下信息:

我希望标签与输入保持一致。

library(shiny)
library(shinyWidgets)
library(shinydashboard)

ui <- fluidPage(

  column(width = 8, 

    tabBox(width = 12, 

      tabPanel(
        'Items', 

        fluidRow(
          style = 'margin:2px',

          wellPanel(
              tags$form(class = 'form-horizontal',
                tags$b('Filter items'),

                tags$div(
                  class = 'form-group',

                  tags$label(class = "col-sm-3 control-label", `for` = 'type', "By type:"), 
                  column(
                    width = 9, 
                    pickerInput(
                      inputId = 'type', label = '', 
                      choices = character(0), 
                      multiple = T
                    ))), 

                tags$div(
                  class = 'form-group',

                  tags$label(class = "col-sm-3 control-label", `for` = 'name', "By name:"), 
                  column(
                    width = 9, 
                    searchInput(
                      inputId = 'name', label = '',
                      placeholder = "Search by name",
                      btnSearch = icon("search"),
                      btnReset = icon("remove")
                    ))
                  )
                )
              )
          )
      )
    )
  ) #/column 8
)

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

shinyApp(ui, server)

除了column(width = 3, ...)之外我尝试过的:

  • 弹性:tags$div(class = 'form-group', style = 'display:flex; align-items:center;', ...)
  • 职位:tags$div(class = 'form-group', style = 'display:table; position:absolute;', tags$label(class = "col-sm-3 control-label", style = 'display;table-cell; vertical-align:middle;', ...), ...)

我不精通 HTML,所以需要大量猜测。达到预期结果的最佳方法是什么?任何帮助将不胜感激。

【问题讨论】:

    标签: html css r shiny


    【解决方案1】:

    也许只是将标签面板排列成多行,然后 在这些里面用列排列你喜欢的东西。

    #
    #
    library(shinydashboard)
    library(shiny)
    library(shinyWidgets)
    
    ui <- fluidPage(
        tabBox(
            tabPanel(title = "Items",
                     wellPanel(
                         fluidRow(column(width = 12,"Filter Items")),
                         br(),
                         fluidRow(
                             column(width = 3,"By Type: "),
                             column(width = 9,
                                    pickerInput(inputId = "choices.type",
                                                choices = character(0),
                                                multiple = TRUE))
                                ),
                         fluidRow(
                             column(width = 3,"By Name: "),
                             column(width = 9,
                                    searchInput(inputId = "seach.name",
                                                placeholder = "Search",
                                                btnSearch = icon("search"),
                                                btnReset =  icon("remove")))
                                )
                            )
    
                    )
            )
    )
    
    server <- function(input, output, session) {
    
    }
    
    shinyApp(ui, server)
    

    【讨论】:

    • 谢谢安德烈,我确实想过使用column(),但想看看form-horizontal 是否也可以。对于后者,我必须在标签标签内添加一个换行符以使其与输入对齐,但这似乎是一个 hacky 解决方案,所以我想在这里问。
    猜你喜欢
    • 2011-11-16
    • 1970-01-01
    • 2013-05-29
    • 2012-02-10
    • 1970-01-01
    • 2016-10-08
    • 2012-10-10
    • 1970-01-01
    相关资源
    最近更新 更多