Problem Description

对于一个shiny 的应用程序,我想在我的应用程序中以类似于行的布局并排显示多个selectInputs.不幸的是,如果标签中出现 break line , destruct 了应用程序的流程,则 Select 字段不会对齐.

Situation

这是我的示例代码,我在selectInput的描述中修改了示例:

## Only run examples in interactive R sessions
if (interactive()) {
  
  
  
  # demoing group support in the `choices` arg
  shinyApp(
    ui = fluidPage(
      mainPanel(
        flowLayout(
          selectInput("state", "Choose a state:",
                      list(`East Coast` = list("NY", "NJ", "CT"),
                           `West Coast` = list("WA", "OR", "CA"),
                           `Midwest` = list("MN", "WI", "IA")),
          ),
          selectInput("stat2", "Variable description with a way longer description to enforce linebreak:",
                      list(`East Coast` = list("NY", "NJ", "CT"),
                           `West Coast` = list("WA", "OR", "CA"),
                           `Midwest` = list("MN", "WI", "IA")),
          )),# end of inputs
        
        textOutput("result"),
        width = 12
      )),
    server = function(input, output) {
      output$result <- renderText({
        paste("You chose", input$state)
      })
    }
  )
}

其结果是:

Failed formatting

Target

我希望输入字段始终处于相同的高度级别,如下所示:

wishful Layout

splitLayout kind of does this, but it breaks down if the page is to narrow for the labels and adds y-scrollers which are complicating the UI, especially for bigger Labels: Splitlayout

不幸的是,我没有WebDev方面的经验,因此有点不知所措.有人能帮我解决这个问题吗?

推荐答案

CSS起到了作用.

style = "display:flex;align-items:flex-end"

在flowLayout中包含这种样式是否有助于解决问题?

if (interactive()) {
  
  
  
  # demoing group support in the `choices` arg
  shinyApp(
    ui = fluidPage(
      mainPanel(
        flowLayout(
          style = "display:flex;align-items:flex-end",
          selectInput("state", "Choose a state:",
                      list(`East Coast` = list("NY", "NJ", "CT"),
                           `West Coast` = list("WA", "OR", "CA"),
                           `Midwest` = list("MN", "WI", "IA")),
          ),
          selectInput("stat2", "Variable description with a way longer description to enforce linebreak:",
                      list(`East Coast` = list("NY", "NJ", "CT"),
                           `West Coast` = list("WA", "OR", "CA"),
                           `Midwest` = list("MN", "WI", "IA")),
          )),# end of inputs
        
        textOutput("result"),
        width = 12
      )),
    server = function(input, output) {
      output$result <- renderText({
        paste("You chose", input$state)
      })
    }
  )
}

R相关问答推荐

在与ggplot 2和网格的最佳匹配线上绘制箭头

如何将y轴设置为在ggplot 2中x=0处与x轴相交?

使用log 10转换绘制geom_smooth

R:对于没有数据的缓冲区,加权平均值为0

geom_raster不适用于x比例中超过2,15的值

如何根据包含相同值的某些列获取总额

将非重复序列高效转换为长格式

如何将旋转后的NetCDF转换回正常的纬度/经度网格,并使用R?

在R中将特定列的值向右移动

为什么当用osmdata映射R时会得到相邻状态?

找出二叉树中每个 node 在R中的深度?

使用for循环和粘贴创建多个变量

比较理论阿尔法和经验阿尔法

如何在PackageStatus()中列出&q;不可用的包&q;?

在R中,我如何使用滑动窗口计算位置,然后进行过滤?

如何使用FormC使简单算术运算得到的数字是正确的?

在R中的数据框上使用Apply()函数时,如何保留非数字列?

按组跨多列创建伪变量

如何在内联代码中添加额外的空格(R Markdown)

如何使用包metaviz更改标签的小数位数?