-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayout.Rmd
159 lines (126 loc) · 3 KB
/
layout.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
---
title: "Layout"
description: |
Organize the elements in the UI
output:
distill::distill_article:
toc: true
toc_float: true
toc_depth: 4
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, eval = FALSE)
```
Start with a new file: `intro-shiny/babynames/01-layout/app-baby-01.R`
With inputs and outputs established in the UI, we can arrange them with various layout functions.
For readability, each of the existing UI elements will be set to its own variable in the global section, above `ui`.
```{r}
title <- titlePanel("U.S. Baby Names")
src <- p("Source:",
tags$a(href = "https://www.ssa.gov/oact/babynames/limits.html",
"Social Security Administration"))
txt_box <- textInput("name",
label = "Enter name",
placeholder = "Jane")
txt_disp <- textOutput("name_entered")
tbl_disp <- tableOutput("main_table")
```
# Pre-defined Layouts
Some UI functions are pre-set like `sidebarLayout()`.
```{r}
ui <- fluidPage(
title,
src,
# A sidebarLayout with sidebarPanel and mainPanel
sidebarLayout(
sidebarPanel(),
mainPanel()
)
)
```
Place content within `sidebarPanel()` and `mainPanel()`.
```{r}
ui <- fluidPage(
title,
src,
# A sidebarLayout with sidebarPanel and mainPanel
sidebarLayout(
sidebarPanel(
txt_box,
txt_disp
),
mainPanel(
tbl_disp
)
)
)
```
# Rows and Columns
In lieu of pre-defined layouts, you can build your layout with rows and columns using `fluidRow()` or `fixedRow()`. `columns()` are created within `*Row()` .
<aside>
Set column widths using an integer between 1 and 12. The maximum number of units within a row is 12.
</aside>
You can also embed rows and columns within pre-defined layouts like in the example below.
```{r}
ui <- fluidPage(
title,
src,
# A sidebarLayout with sidebarPanel and mainPanel
sidebarLayout(
sidebarPanel(
txt_box,
txt_disp
),
mainPanel(
# create columns within fluidRow or fixedRow
fluidRow(
column(
width = 6,
h3("Table"),
tbl_disp
),
column(
width = 6,
# add a place holder for a plot
h3("Plot"),
plotOutput("plot")
)
)
)
)
)
```
While we're in the UI, let's add some additional inputs to the sidebar.
```{r}
ui <- fluidPage(
title,
src,
# sidebar layout with sidebarPanel and mainPanel
sidebarLayout(
sidebarPanel(
txt_box,
txt_disp,
# add a dropdown menu to select state
selectInput("state",
label = 'Select State',
choices = unique(df$state),
selected = 'Washington')
),
mainPanel(
fluidRow(
column(
width = 6,
h3("Table"),
tbl_disp
),
column(
width = 6,
# add a place holder for a plot
h3("Plot"),
plotOutput("plot")
)
)
)
)
)
```