-
Notifications
You must be signed in to change notification settings - Fork 0
/
original.R
160 lines (127 loc) · 4.41 KB
/
original.R
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
156
157
158
159
# ===============================================
# Fill in the following fields
# ===============================================
# Title:
# Description:
# Author:
# Date:
# ===============================================
# Packages
# ===============================================
library(tidyverse)
# ===============================================
# Import data
# ===============================================
# for demo purposes of the "template", we use data starwars
# (but you will have to replace this with the data in "simpsons-transcripts.txt")
dat <- dplyr::starwars
# ===============================================
# Define "ui" for application
# ===============================================
ui <- fluidPage(
titlePanel("Title of your app"),
fluidRow(
# replace with your widgets
column(3,
p(em("Input widgets")),
radioButtons(inputId = "choose",
label = "Choose one option",
choices = c("option 1" = "opt1",
"option 2" = "opt2",
"option 3" = "opt3"),
selected = "opt1")
),
# replace with your widgets
column(3,
p(em("Input widgets")),
selectInput(inputId = "select",
label = "Make a selection",
choices = c("select 1" = "sel1",
"select 2" = "sel2",
"select 3" = "sel3"),
selected = "sel1")
),
# replace with your widgets
column(3,
p(em("Input widgets")),
radioButtons(inputId = "arrange",
label = "Order bars by:",
choices = c("decreasing freq" = "arr_dec",
"increasing freq" = "arr_inc",
"alphabetical a-z" = "arr_a2z",
"alphabetical z-a" = "arr_z2a"),
selected = "arr_dec")
),
# replace with your widgets
column(3,
p(em("Input widgets")),
sliderInput(inputId = "size",
label = "Size",
min = 1,
max = 10,
value = 1),
checkboxInput(inputId = "facets",
label = strong("Facet by gender"),
value = FALSE)
)
),
hr(),
tabsetPanel(type = "tabs",
tabPanel("Analysis1",
h3("What kind of analysis1?"),
plotOutput("plot1"),
hr(),
dataTableOutput('table1')),
tabPanel("Analysis2",
h3("What kind of analysis2"),
plotOutput("plot2"),
hr(),
verbatimTextOutput('table2'))
)
)
# ===============================================
# Define Server "server" logic
# ===============================================
server <- function(input, output) {
# you may need to create reactive objects
# (e.g. data frame to be used in plot1)
dat_freq <- reactive({
dat %>% group_by(sex) %>% count()
})
# ===============================================
# Outputs for the first TAB
# ===============================================
# code for plot1
output$plot1 <- renderPlot({
# replace the code below with your code!!!
ggplot(data = dat_freq(), aes(x = sex, y = n)) +
geom_col()
})
# code for numeric summaries of frequencies
output$table1 <- renderDataTable({
# replace the code below with your code!!!
dat_freq()
})
# ===============================================
# Outputs for the second TAB
# ===============================================
# code for plot2
output$plot2 <- renderPlot({
# replace the code below with your code!!!
p1 = ggplot(data = dat, aes(x = height, y = mass)) +
geom_point(size = input$size)
if (input$facets) {
p1 = p1 + facet_wrap(~ gender)
}
p1
})
# code for statistics
output$table2 <- renderPrint({
# replace the code below with your code!!!
summary(dat$height)
})
}
# ===============================================
# Run the application
# ===============================================
shinyApp(ui = ui, server = server)