我正在创建一个使用闪亮的应用程序来处理用户输入数据并计算某些患者统计数据,然后再渲染结果值。我在下面粘贴了我的ui.R代码的虚拟片段。我试图找到一种方法来通过患者访问对textInput框进行分组。有没有办法对textInput框进行分组,这样每行代表一个单独的患者访问,textInput框并排排列?
我希望将textInput框显示为:
Visit1
[BMI1文本框] [胆固醇1文本框] [心率1文本框]
Visit2
[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")
)
)
)
答案 0 :(得分:1)
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
提供一个定义单元格宽度的向量(请参阅help page)。