r - 在闪亮中分组文本输入框
问题描述
我正在使用 Shiny 创建一个应用程序,该应用程序处理用户输入数据并计算某些患者统计数据,然后呈现结果值。我在下面粘贴了我的 ui.R 代码的虚拟片段。我正在尝试找到一种通过患者访问对 textInput 框进行分组的方法。有没有办法对 textInput 框进行分组,这样每一行将代表一个单独的患者访问,其中 textInput 框并排对齐?
我希望将 textInput 框显示为:
Visit1
[ BMI1 文本框 ] [胆固醇 1 文本框] [心率 1 文本框]
访问2
[BMI2 文本框] [胆固醇 2 文本框] [心率 2 文本框]
ui <- fluidPage(# App title ----
titlePanel("Dummy Patient Analysis"),
# Sidebar layout with input and output definitions ----
sidebarLayout(
sidebarPanel(
#### Visit 1 #######
textInput(
inputId = "bmi1",
label = "BMI1",
value = 2
),
textInput(
inputId = "chol1",
label = "cholesterol 1",
value = 5
),
textInput(
inputId = "heart_rate1",
label = "Heart Rate",
value = 40
),
#### Visit 2 #######
textInput(
inputId = "bmi2",
label = "BMI2",
value = 2
),
textInput(
inputId = "chol2",
label = "cholesterol 2",
value = 7
),
textInput(
inputId = "heart_rate2",
label = "Heart Rate",
value = 42
),
actionButton("process", "Estimate")
),
mainPanel(
tableOutput("view"),
verbatimTextOutput("summary")
)
)
)
解决方案
splitLayout
旨在以最少的努力完成这种事情。只需将您想要的每组输入并排包装splitLayout()
即可实现您正在寻找的内容,如下所示:
library(shiny)
ui <- fluidPage(
titlePanel("Dummy Patient Analysis"),
sidebarLayout(
sidebarPanel(
splitLayout(
textInput(inputId = "bmi1", label = "BMI1", value = 2),
textInput(inputId = "chol1", label = "cholesterol 1", value = 5),
textInput(inputId = "heart_rate1", label = "Heart Rate", value = 40)
),
splitLayout(
textInput(inputId = "bmi2", label = "BMI2", value = 2),
textInput(inputId = "chol2", label = "cholesterol 2", value = 7),
textInput(inputId = "heart_rate2", label = "Heart Rate", value = 42)
),
actionButton("process", "Estimate")
),
mainPanel(
tableOutput("view"),
verbatimTextOutput("summary")
)
)
)
server <- function(input, output) {}
shinyApp(ui, server)
如果您不希望这些框占据整个侧边栏,您还可以提供splitLayout
一个定义单元格宽度的向量(请参阅帮助页面)。
推荐阅读
- python - 悉尼的 Choropleth 地图
- javascript - 退货有错误(我不明白为什么
- jquery - 实现 data.sort 按标题对 json 进行排序,不断收到“未定义”错误。不知道我做错了什么
- python - 如果 100,则 Round 返回 (100, 1)
- flutter - 如何在 Flutter 中获取实时通知
- c# - UTF-16 错误,如何解决无法识别的转义序列?
- android - Android Google Map 有错误的 cert_fingerprint
- javascript - 如何让我的随机生成器在特定结果上输出某个网站背景
- json - Flutter 使用 JSON 设置 AppBar 标题显示错误
- javascript - 如何在 EmberJs 操作中处理右键单击“在新选项卡中打开”?