r - 如何格式化 tagList 以在 RShiny 中进行按列布局?
问题描述
我正在制作一个应用程序,其中我有可变数量的输入字段。这些字段是交替的selectizeInput()
和textInput()
字段,其中每组两个输入的 ID 都会递增 1。我从 R Shiny 获得了一些灵感来生成这个:如何动态附加任意数量的输入小部件
现在,我想更改我的 taglist 中输入小部件的布局。使用当前代码,inputTagList
附加 using中的所有标签tagAppendChild()
都打印在我的应用程序中的先前代码下方。
我希望它们打印在两列中,其中第一个标签在左上角,第二个在右上角,第三个在第二行左边,然后第二行在右边,等等。这意味着所有selectizeInput()
字段,命名为namesInput
,在左边,右边是textInput()
名为 的字段groupInput
。
我从我的应用程序中提取了基本项目来制作一个可运行的示例:
library(shiny)
ui <- fluidPage(
mainPanel(sliderInput('numGroups','Number of Groups',min=1,max=20,value=2,step=1),
uiOutput("allInputs"))
)
server <- function(input, output) {
output$allInputs <- renderUI({
inputTagList <- NULL
inputTagList <- tagList()
## Define options for each input field
opts <- as.list(paste0('Level',1:5))
names(opts) <- sapply(opts,function(x) x)
## Get number of groups from sliderinput
k <- input$numGroups
for(i in 1:k) {
# Define unique input id and label
newInputId <- paste0("group", i)
newInputLabel <- paste("Group levels", i)
newInputId2 <- paste0("name", i)
newInputLabel2 <- paste("Group name", i)
newInputValue2 <- paste("Group",i)
# Define new input
namesInput <- selectizeInput(newInputId, newInputLabel,
choices=opts,
multiple=T)
groupInput <- textInput(newInputId2, label = newInputLabel2, value = newInputValue2)
# Append new input to list of existing inputs
inputTagList <- tagAppendChild(inputTagList, namesInput)
inputTagList <- tagAppendChild(inputTagList, groupInput)
} # return list of inputs
inputTagList
})
}
# Run the application
shinyApp(ui = ui, server = server)
谢谢你的想法!
解决方案
推荐阅读
- postgresql - .Net 核心和 Npgsql 查询错误 A 命令已在进行中
- node.js - 如何使用 Node.js 从 MongoDB 匹配字段并获取其 objectId?
- cordova - 使用 cordova-plugin-advanced-http 请求超时
- excel - 将具有特定格式的单元格从其他工作表中检索到 Excel 中的新工作表中
- docker - 如何在 Docker 中使用 Wine 运行我的 Win32 应用程序?
- ios - 如何在 UITableView 中替换自定义单元格样式?
- r - 用于重复测量的具有嵌套分组的条形图
- javascript - 带有几个变量的简单 HTML 音轨
- multithreading - 骆驼文件组件无法使用多个线程并行消耗
- javascript - 如何在 javascript 中同时运行验证(emailid,contactno)