[英]Grouping textInput box in shiny
I am working on creating an app using shiny that processes user input data and calculates a certain patient statistics and later renders the result values. 我正在使用Shiny创建一个应用程序,该应用程序处理用户输入数据并计算某些患者统计信息,然后呈现结果值。 I have pasted a dummy snippet of my ui.R code below. 我在下面粘贴了我的ui.R代码的虚拟片段。 I am trying to find a way to group the textInput boxes by patient visits. 我正在尝试找到一种按患者就诊对textInput框进行分组的方法。 Is there a way to group the textInput boxes, such that each line will represent a separate patient visit with textInput boxes aligned side by side? 有没有一种方法可以对textInput框进行分组,以便每一行都可以将textInput框并排对齐,代表单独的患者就诊?
I am hoping to display the textInput boxes as: 我希望将textInput框显示为:
Visit1 Visit1
[ BMI1 textbox ] [cholesterol 1 textbox] [Heart Rate 1 textbox] [BMI1文本框] [胆固醇1文本框] [心率1文本框]
Visit2 Visit2
[ BMI2 textbox ] [cholesterol 2 textbox] [Heart Rate 2 textbox] [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
is designed to do exactly this kind of thing with minimal effort. splitLayout
旨在以最小的努力来完成这种事情。 Just wrap each set of inputs you want side-by-side with splitLayout()
to achieve what you're looking for, like so: 只需将您想要的每组输入与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)
If you don't want the boxes to take up the entire sidebar, you can also supply splitLayout
with a vector that defines cell widths (see help page ). 如果您不希望这些框占用整个侧边栏,则还可splitLayout
提供一个定义单元格宽度的矢量(请参阅帮助页面 )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.