【问题标题】:R Shiny: Dynamic column layout to prevent whitespaceR Shiny:动态列布局以防止空白
【发布时间】:2018-07-27 15:09:27
【问题描述】:

我有一个带盒子的闪亮仪表板应用程序。该框包含两个元素,一个滑块和一个开关。它们应该显示在一行中。 当我缩小时,我不想在行尾获得额外的空白,而是让滑块占用更多空间。

似乎column() 不是布局我的应用程序的正确方法,但是我没有找到在没有column() 的情况下将我的元素放在一行中的方法。

我怎样才能将元素放在一行中,并且让开关占用的空间不超过它需要的空间?

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



ui <- dashboardPage(header = dashboardHeader(),
                    sidebar = dashboardSidebar(),
                    body = dashboardBody(  column(12, box(width="100%", 
column(width=9, sliderInput("hi", label = "I like sliding", min = 1, max = 
42, value = 20,width="100%")),
                                                         column(width=3, 
switchInput("ho", label ="Switch me tonight", width="100%")))))
)


server <- function(input, output) { 
}

shinyApp(ui, server)

【问题讨论】:

    标签: r layout shiny


    【解决方案1】:

    在下面的样式参数中使用width

    library(shiny)
    library(shinydashboard)
    library(shinyWidgets)
    
    ui <- dashboardPage(header = dashboardHeader(),
                        sidebar = dashboardSidebar(),
                        body = dashboardBody(box(width=12, 
                                                   div(style="display: inline-block; width: 92%;",sliderInput("hi", label = "I like sliding", min = 1, max = 42, value = 20)),
                                                   div(style="display: inline-block; width: 7%;",switchInput("ho", label ="Switch me tonight"))
    
    
                        ))
    )
    
    
    server <- function(input, output) { }
    
    shinyApp(ui, server)
    

    【讨论】:

    • 谢谢,但是当我使用您的宽度参数放大时,开关不在框中。当我使用不同的参数时,我得到了空格。我可以以某种方式将 switchInput 对齐到行尾吗? (也许以后还会垂直居中?)
    猜你喜欢
    • 2019-03-24
    • 1970-01-01
    • 2015-04-03
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多