【问题标题】:div align right checkboxInput in shiny dashboard not workingdiv align right checkboxInput 在闪亮的仪表板中不起作用
【发布时间】:2016-09-30 13:07:18
【问题描述】:

我闪亮的仪表板有 checkboxInput,我正试图将它与盒子项目的标题对齐。对于较小的框(宽度为 6),对齐是正确的,但是对于宽度为 12 的框,无论我如何重新对齐列值,复选框输入都保留在框的中间。代码如下:

library(shiny)
library(shinydashboard)


ui <- dashboardPage(
    skin = "green",
    dashboardHeader(
        title = "TEST", titleWidth = 225
        ),
    dashboardSidebar(
        menuItem("TRENDS", tabName = "vactr", icon = shiny::icon("line-chart"))
        ),
    dashboardBody(
        tabItems(
            tabItem(
                tabName = "vactr",
                fluidRow(
                    box(
                        width = 12, status = "info", title = 
                            fluidRow(
                                column(6, "Trend - Usage of space",br(),
                                       div(downloadLink("downloadspacetrend", "Download this chart"), style = "font-size:70%", align = "left")),
                                column(6,
                                       div(checkboxInput(inputId = "spacetrendcheck", "Add to reports", value = FALSE),style = "font-size:70%",float = "right", align = "right", direction = "rtl"))
                                ),
                        div(plotOutput("spacetrend"), width = "100%", height = "400px", style = "font-size:90%;"),
                        uiOutput("spacetrendcomment")
                    )
                )

                )
            )
        )
    )


server <- function(input, output, session) {

}

shinyApp(ui = ui, server = server)

我希望将“添加到报告”复选框放在框的右端。我尝试使用浮点数、方向参数(有和没有),但没有得到所需的输出。

【问题讨论】:

    标签: checkbox shiny right-align


    【解决方案1】:

    您的问题有以下原因:标题标题的宽度未设置为框的整个宽度。相反,它的宽度是根据它包含的元素计算的。这使得列(标题宽度为 50%)也取决于元素。但是,您的元素并没有那么大,因此生成的 div 本身很好地划分为两个同样大的列,但它们加在一起并不跨越整个框的宽度。

    您可以将标题宽度固定为100%(框标题宽度),结果告诉列要那么大,无论它们的内容是什么。 这是一行加法。

    请注意,以下代码中的样式添加会影响所有框标题。但我相信这从来都不是问题。

    library(shiny)
    library(shinydashboard)
    
    
    ui <- dashboardPage(
      skin = "green",
      dashboardHeader(
        title = "TEST", titleWidth = 225
      ),
      dashboardSidebar(
        menuItem("TRENDS", tabName = "vactr", icon = shiny::icon("line-chart"))
      ),
      dashboardBody(
        tabItems(
          tabItem(tabName = "vactr",
            fluidRow(
              box(width = 12, status = "info", title = 
                fluidRow(
                  tags$style(".box-title {width: 100%;}"),
                  column(6, "Trend - Usage of space",br(),
                    div(downloadLink("downloadspacetrend", "Download this chart"), style = "font-size:70%", align = "left")),
                  column(6,
                    div(checkboxInput(inputId = "spacetrendcheck", "Add to reports", value = FALSE),style = "font-size:70%",float = "right", align = "right", direction = "rtl"))
                ),
                div(plotOutput("spacetrend"), width = "100%", height = "400px", style = "font-size:90%;"),
                uiOutput("spacetrendcomment")
              )
            )
          )
        )
      )
    )
    
    server <- function(input, output, session) {}
    
    shinyApp(ui = ui, server = server)
    

    【讨论】:

    • 谢谢...从来不知道这些选项...再次非常感谢。可爱,更正已应用于我在应用程序中的所有选项卡和框。
    猜你喜欢
    • 2019-11-18
    • 1970-01-01
    • 2020-10-27
    • 2022-01-02
    • 2015-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-12
    相关资源
    最近更新 更多