带有光泽的selectInput旁边的标签

时间:2015-11-27 14:58:21

标签: css r user-interface label shiny

我有这样一个闪亮的应用程序:

server.R:

    library(shiny)

    function(input, output) { NULL }

和ui.R:

    library(shiny)  


    pageWithSidebar( 

       headerPanel("side-by-side"), 

     fluidRow(

        column(2),
        column(4,
           wellPanel(
               selectInput(inputId = "options", label = "some text", 
                           choices = list(a = 0, b = 1)))   
           )
      ),

      fluidRow( 
         h3("bla bla")
     )
    )

我希望在它旁边有selectInput标签,而不是上面。你知道怎么做吗?

我发现了这个:Positioning Shiny widgets beside their headers 但它对我不起作用。

1 个答案:

答案 0 :(得分:7)

有多种方法可以做到这一点,其中一个方法是:

library(shiny)

server <- shinyServer(function(input, output) { NULL })
ui <- shinyUI(
  pageWithSidebar( 

    headerPanel("side-by-side"), 

    sidebarPanel(
    fluidRow(
      tags$head(
        tags$style(type="text/css", "label.control-label, .selectize-control.single{ display: table-cell; text-align: center; vertical-align: middle; } .form-group { display: table-row;}")
      ),
      column(2),
      column(4,
               selectInput(inputId = "options", label = "some text", 
                           choices = list(a = 0, b = 1))
      )
    )),
    mainPanel(
    fluidRow( 
      h3("bla bla")
    ))
  )
)

shinyApp(ui=ui,server=server)

如果您不想使用shinys默认CSS,您可以将标签留空并在其旁边创建一个标签,而不是强制将现有标签放在一边。