r - 在 Shiny 中创建多个内联输入组
问题描述
我想内联几组输入,我不知道提前多少。我已经看到了所有类似的问题,但没有任何帮助。我的代码是这样的:
library(shiny)
ui <- fluidPage(
tags$head(
tags$style(type="text/css", ".inline label{ display: table-cell; text-align: left; vertical-align: middle; }
.inline .form-group{display: table-row;}")
),
uiOutput("out")
)
server <- function(input, output){
set.seed(1543)
num <- 1:runif(1, 1, 6)
show <- function(i){
tagList(
numericInput(i, paste(c(1:i), collapse = ""), value = 0),
selectInput(paste("text", i), "", choices = c("min", "max"))
)
}
output$out <- renderUI({
tags$div(class = "inline",
lapply(num, function (i) {
show(i)
})
)
})
}
shinyApp(ui = ui, server = server)
所以当“num”是随机的时,我试图为每个“num”做两个输入。但是 selectInput 出现在新行中。
如何为每个数字制作一行(label-numericInput-selectInput)?注意:每行的标签可以有不同的长度,所以盒子应该右对齐。
提前非常感谢!
解决方案
最简单的方法是style = "display: inline-block;vertical-align:top;"
在输入中添加并在最后添加断线。
library(shiny)
ui <- fluidPage(
tags$head(
tags$style(type="text/css", ".inline label{ display: table-cell; text-align: left; vertical-align: middle; }
.inline .form-group{display: table-row;}")
),
uiOutput("out")
)
server <- function(input, output){
set.seed(1543)
num <- 1:runif(1, 1, 6)
show <- function(i){
tagList(
div(numericInput(i, paste(i), value = 0), style = "display: inline-block;vertical-align:top;"),
div(selectInput(paste("text", i), "", choices = c("min", "max")), style = "display: inline-block;vertical-align:top;"),
br()
)
}
output$out <- renderUI({
tags$div(class = "inline",
lapply(num, function (i) {
show(i)
})
)
})
}
shinyApp(ui = ui, server = server)
推荐阅读
- continuous-integration - 如何为 Circle CI orb 中的作业创建多个执行器?
- matlab - MATLAB 中的线性插值
- ruby - Ruby - IMAP 迭代多个文件夹/选择多个文件夹
- javascript - 带有参数的 es7 函数 decotators 以返回循环
- javascript - 如何在浏览器中安全地存储 JWT?
- python - 检查熊猫 df 中的值是否在第二个 df 的列中的列表内
- ansible - 恢复使用 Copy 创建的备份文件
- java - 尝试安装现有调试 apk 时出现“未安装应用程序”
- python - 旋转数据框?如何整理 325x1 df
- c# - 在.net 5中使用工厂方法进行依赖注入的对象生命周期