如何使标签和框在闪亮::numericInput 中彼此相邻对齐? [英] How to make label and box align next to each other in shiny::numericInput?

查看:22
本文介绍了如何使标签和框在闪亮::numericInput 中彼此相邻对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以为标签旁边的框创建一个 numericInput() (而不是默认的).

Is it possible to create a numericInput() for shiny where box is next to the label (instead of below it which is the default).

这是一个简单的例子:

library(shiny)

ui <- shinyUI(fluidPage(

    titlePanel("Shiny with lots of numericInput()"),

    sidebarLayout(

        sidebarPanel(
            fluidRow(
                column(6, numericInput("a1", label = "A1", value = 1)),
                column(6, numericInput("b1", label = "B1", value = 1))
            ),
            fluidRow(
                column(6, numericInput("a2", label = "A2", value = 2)),
                column(6, numericInput("b2", label = "B2", value = 2))
            )
        ),

        mainPanel(
            p('something interesting')
        )
    )
))

server <- function(input, output) {}

shinyApp(ui, server)

这会产生 4 行:第一行用于标签A1"和B1",第二行用于相应的框,等等.如果我尝试调整 width 参数也无济于事numericInput().

This results in 4 lines: first line for the labels "A1" and "B1", second line for the corresponding boxes, etc. It does not help if I try to adjust the width parameter of numericInput().

(可惜我不太懂html和css直接修改input widget的class.)

(Unfortunately I do not really know html and css to modify the class of the input widget directly.)

这里是一个类似的问题.但我可以使用fluidRow() 处理同一行,我希望标签也位于同一行.

Here is a similar issue. But I can handle the same row with fluidRow(), I want the labels to be in the same row as well.

推荐答案

好问题,这也与其他控件有关.我感觉到你的痛苦.下面的解决方案是我使用的,但并不理想.如果可以将其设置为控件中的闪亮参数会更好.HTML/CSS 解决方案很可能也会看起来更好.

Good question, that is also relevant to other controls. I feel your pain. The solution below is what I use, but is not ideal. It would be better if this could be set as a shiny parameter in the control. An HTML/CSS solution will most likely also look better.

 library(shiny) 
ui <- shinyUI(fluidPage(
  titlePanel("Shiny with lots of numericInput()"), 
   sidebarLayout(  
     sidebarPanel(
        fluidRow(
            column(2,  HTML('<b>A1</b>')),
            column(4, numericInput("a1", label = NULL, value = 1)),
            column(2, HTML('<b>B1</b>')), 
            column(4, numericInput("b1", label = NULL, value = 1))
        ),
        fluidRow(
            column(2, HTML('<b>A2</b>')),
            column(4, numericInput("a2", label = NULL, value = 1)),
            column(2,  HTML('<b>B2</b>')), 
            column(4, numericInput("b2", label = NULL, value = 1))
        )  
    ), 
    mainPanel(
        p('something interesting')
    )
))) 
server <-   function(input, output) { } 
shinyApp(ui, server)

这篇关于如何使标签和框在闪亮::numericInput 中彼此相邻对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆