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. I have pasted a dummy snippet of my ui.R code below. I am trying to find a way to group the textInput boxes by patient visits. 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?
I am hoping to display the textInput boxes as:
Visit1
[ BMI1 textbox ] [cholesterol 1 textbox] [Heart Rate 1 textbox]
Visit2
[ BMI2 textbox ] [cholesterol 2 textbox] [Heart Rate 2 textbox]
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. Just wrap each set of inputs you want side-by-side with splitLayout()
to achieve what you're looking for, like so:
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 ).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.