【问题标题】:Arranging textInput elements in two or more columns in a shiny app在闪亮的应用程序中将 textInput 元素排列在两列或多列中
【发布时间】:2019-03-12 12:51:32
【问题描述】:

Shiny GUI 现在看起来如附图所示。 我想优化 sidebarPanel 中两列或更多列中 (>30) 个 textInput 元素的空间和排列。

如何使用 textInput 元素设置两列 - 有我可以使用的表格类型吗?

textInput的高度怎么改,我看到只有'width'可以编辑?

如何优化 textInput 元素排列:即元素之间的距离、字体大小等?

【问题讨论】:

    标签: r shiny textinput


    【解决方案1】:

    代码显示了两列 15 行(30 个文本输入)侧边栏设计。基本上,您编写一个函数来为一行生成 UI,然后使用lapply 一次又一次地调用它,无论您想要多少行。您可以将此方法用于任意数量的列。

    output$test 展示了如何从所有输入中提取值。

    library(shiny)
    
    textInputFUN <- function(uid) {
      fluidRow(
        column(6,
          textInput(paste0("par_", uid), label = paste0("par_", uid))
        ),
        column(6,
          textInput(paste0("par_", uid+1), label = paste0("par_", uid+1))
        )
      )
    }
    
    input_rows <- 15
    input_ids <- seq(1, input_rows*2, by = 2)
    
    shinyApp(
      ui = fluidPage(
        sidebarLayout(
          sidebarPanel(
            lapply(seq_len(input_rows), function(x) {
              textInputFUN(uid = input_ids[x])
            })
          ),
          mainPanel(
            verbatimTextOutput("test")
          )
        )
      ),
      server = function(input, output, session) {
        output$test <- renderPrint({
          sapply(paste0("par_", seq_len(input_rows*2)), function(x) input[[x]])
        })
      }
    )
    

    【讨论】:

    • 因为我最终只需要 13 个参数,所以我手动完成了,但我使用了 'fluidRow(column(),column())' 的想法,谢谢!
    猜你喜欢
    • 2016-08-22
    • 2020-04-12
    • 2018-11-01
    • 2020-03-05
    • 2016-11-17
    • 2021-02-04
    • 2014-12-29
    • 2011-02-21
    • 2022-01-05
    相关资源
    最近更新 更多