R, Shiny : 内联 selectInput

R, Shiny : Inline selectInput

1 ) 我们如何将 selectInput 放在另一个旁边?我试过了:

# style.css
.general {
display: inline-block;
margin-left: auto;
margin-right: auto;
height: auto;
width : auto ;
white-space: nowrap ;}

# ui.R
...
tags$div(class = "general", selectInput(...), selectInput(...))
...

但是没用。

2) 我们如何将 selectInput 的标签放置在 selectInput 本身旁边?我找到了这个主题 Positioning Shiny widgets beside their headers 但这是为应用程序的所有 selectInput 设计的。我没有设法将 tags$style(...) 中提供的代码用于我的一个 selectInput 应用程序,而不是所有应用程序。我们该怎么做?

谢谢。

我自己回答问题 1),举个简单的例子:

# style.css
.divleft {
  float : left;
  width : 50%;
}

.clearl {
  clear: left;
}

# ui.R
library(shiny)

shinyUI(fluidPage(
  tagList(
    tags$head(
      tags$link(rel="stylesheet", type="text/css",href="style.css")
    )
  ),
    sidebarLayout(
      sidebarPanel(
        selectInput("s1", "Select 1", 1:10),
        tags$div(
          tags$div(class = "divleft", selectInput("s2", label = "Select 2", 1:5, width = validateCssUnit("70%"))),
          tags$div(class = "divleft", selectInput("s3", label = "Select 3", 1:5, width = validateCssUnit("70%")))
        ),
        tags$div(class = "clearl",
                selectInput("s4", "Select 4", 1:5)
                 )
        , width = 3),
      mainPanel(
        h3("Example")
      )
    )
  )
)

# server.R
shinyServer(function(input, output, session) { })

只需尝试使用一个流畅的行和多个列。由于总的流体行宽 = 12,您最多可以一个接一个地放置 12 列,而无需任何额外的 css。例如:

fluidRow(
column(6, selectInput("S1", label = "S1")),
column(6, selectInput("S2", label = "S2"))
)