R Shiny:动态列布局以防止空格

时间:2018-07-27 15:09:28

标签: r layout shiny

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

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)

1 个答案:

答案 0 :(得分: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)

enter image description here