ui.R
2025-07-20 本文已影响0人
LET149
ui : User Interface
1. 基本格式
shinyUI(fluidPage(
titlePanel(),
sidebarLayout(
sidebarPanel(),
mainPanel()
)
) )
1.1 titlePanel()
titlePanel():
用来指定App的名称
出现在整个App界面的最左上角
titlePanel()
1.2 sidebarLayout()
sidebarLayout():
用来指定App界面的主要内容
1.2.1 sidebarPanel()
sidebarPanel():
用来指定方格块内的内容
sidebarPanel()
1.2.2 mainPanel()
mainPanel()
用来指定除了方格块以外部分的内容
mainPanel()
1.2.3 sidebarPanel()和mainPanel()中的书写格式
关于文字的书写:
h1(): 一级标题,用"align="来规定标题放置的位置
h2(): 二级标题,用"align="来规定标题放置的位置
h3(): 三级标题,用"align="来规定标题放置的位置
h4(): 四级标题,用"align="来规定标题放置的位置
h5(): 五级标题,用"align="来规定标题放置的位置
h6(): 六级标题,用"align="来规定标题放置的位置
p(): 文字段落
strong(): 加粗文字
em(): 斜体文字
br(): 空行
code(): 代码
span(, style=): 将文字进行格式改变
img(src="figure_name", height=, width=)
用来插入图片
此图片必须在相应App的文件夹下的www文件夹下
2. 添加控件
添加用来让用户调节或者输入输出的元件
2.1 示例一
shinyUI(fluidPage(
titlePanel("Basic widgets"),
fluidRow(
column(3,
h3("Buttons"),
actionButton("action", label = "Action"),
br(),
br(),
submitButton("Submit")),
column(3,
h3("Single checkbox"),
checkboxInput("checkbox", label = "Choice A", value = TRUE)),
column(3,
checkboxGroupInput("checkGroup",
label = h3("Checkbox group"),
choices = list("Choice 1" = 1,
"Choice 2" = 2, "Choice 3" = 3),
selected = 1)),
column(3,
dateInput("date",
label = h3("Date input"),
value = "2014-01-01"))
),
fluidRow(
column(3,
dateRangeInput("dates", label = h3("Date range"))),
column(3,
fileInput("file", label = h3("File input"))),
column(3,
h3("Help text"),
helpText("Note: help text isn't a true widget,",
"but it provides an easy way to add text to",
"accompany other widgets.")),
column(3,
numericInput("num",
label = h3("Numeric input"),
value = 1))
),
fluidRow(
column(3,
radioButtons("radio", label = h3("Radio buttons"),
choices = list("Choice 1" = 1, "Choice 2" = 2,
"Choice 3" = 3),selected = 1)),
column(3,
selectInput("select", label = h3("Select box"),
choices = list("Choice 1" = 1, "Choice 2" = 2,
"Choice 3" = 3), selected = 1)),
column(3,
sliderInput("slider1", label = h3("Sliders"),
min = 0, max = 100, value = 50),
sliderInput("slider2", "",
min = 0, max = 100, value = c(25, 75))
),
column(3,
textInput("text", label = h3("Text input"),
value = "Enter text..."))
)
))
示例一
- 不同fluidRow()的运行结果之间按行平行放置
- 空间足够的情况下,同一个fluidRow()内部的column()运行结果处于同一行;空间不足则属于不同行
2.2 示例二
shinyUI(fluidPage(
titlePanel("censusVis"),
sidebarLayout(
sidebarPanel(
helpText("Create demographic maps with
information from the 2010 US Census."),
selectInput("var",
label = "Choose a variable to display",
choices = list("Percent White", "Percent Black",
"Percent Hispanic", "Percent Asian"),
selected = "Percent White"),
sliderInput("range",
label = "Range of interest:",
min = 0, max = 100, value = c(0, 100))
),
mainPanel()
)
))
示例二
titlePanel()
sidebarPanel()
mainPanel()