【问题标题】:Why do buttons stay on the same row but textInputs do not?为什么按钮保持在同一行但 textInputs 不?
【发布时间】:2019-04-29 16:13:48
【问题描述】:

我希望按钮和文本输入在同一行。按钮保持在同一行,但 textInputs 进入新行。我不明白为什么。

ui  =   fluidPage(
    textInput("ti1", "TI1"),
    actionButton("Button1", "B1"),
    actionButton("Button2", "B2"),
    textInput("ti2", "TI2")
)

server <- function(input, output) {}

shinyApp(ui= ui, server=server)

【问题讨论】:

  • 我认为this post 可能会对您有所帮助。
  • 可爱可爱!!

标签: r shiny


【解决方案1】:

如下所示,textInput() 将其输出包装在 HTML div 元素中,而 actionButton 则没有。 div 元素的默认行为是在视觉上隔离它们的内容,实际上是在元素前后添加换行符,这就是您所看到的。

textInput("ti1", "TI1")
## <div class="form-group shiny-input-container">
##   <label for="ti1">TI1</label>
##   <input id="ti1" type="text" class="form-control" value=""/>
## </div>

actionButton("Button1", "B1")
##  <button id="Button1" type="button" class="btn btn-default action-button">B1</button>

如果您想在一行上输入多个文本(和/或在各自的行上输入多个操作按钮),您可以使用函数 fluidRow()column() 来实现,如下所示:

ui <- fluidPage(
    fluidRow(
        column(width = 4,
               textInput("ti2", "TI2")),
        column(width = 4,
               textInput("ti1", "TI1"))
    ),
    fluidRow(actionButton("Button1", "B1")),
    fluidRow(actionButton("Button2", "B2"))
)

server <- function(input, output) {}

shinyApp(ui= ui, server=server)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-23
    • 2015-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多