-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
179 lines (148 loc) · 4.65 KB
/
app.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
library(shiny)
library(dplyr)
library(shinyPagerUI)
source(here::here("R", "functions.R"))
tweet_data = readr::read_rds(here::here("data", "tweet_data.rds"))
username_info = readr::read_rds(here::here("data", "username_art.rds"))
### Pulling in logo - shoutout to Sharla for the code
logo = a(href = "", img(src = "logo-animated.gif", alt = "rtistry art gallery", height = "75px"))
ui = tagList(
### Pulling in CSS stylesheet
tags$head(
tags$link(rel = "stylesheet", type = "text/css", href = "style.css")
),
navbarPage(
title = logo,
windowTitle = "rtistry art gallery",
### About Panel
tabPanel(
"ABOUT THE GALLERY",
h2("About the gallery"),
hr(),
p("rtistry art gallery is a shiny app celebrating and showcasing art in all its forms created by the #rstats community. This gallery features tweets posted using the #rtistry hashtag from January 1st, 2021 to March 31st, 2021."),
br(),
br(),
h2("Featured artists"),
selectInput("artist_filter", label = NULL,
choices = c("Artist (A-Z)" = "username",
"Pieces in Collections" = "num_art")),
hr(),
# UI output featuring artists cards
uiOutput("artist_card")
),
### Twitter Collections
tabPanel(
"COLLECTIONS",
id = "collections",
column(
width = 12,
tags$head(tags$script(async = NA, src = "https://platform.twitter.com/widgets.js"))
),
column(
width = 5,
wellPanel(
class = "artist-card",
h3("Selected works"),
p("Filter to specific aRtists of interest or leave as all."),
selectInput("collections_filter",
label = NULL,
choices = c("All", pull_artists(tweet_data)),
selected = "All"),
p("Click through to view all #rtistry pieces."),
pageruiInput('pager', 1, nrow(tweet_data))
)
),
column(
width = 7,
wellPanel(
class = "picture-frame",
uiOutput("tweet")
)
)
),
tabPanel(
"LEARN MORE",
h2("About this app"),
hr(),
column(
width = 12,
wellPanel(
class = "artist-card",
style = "text-align: center",
p("rtistry art gallery was made by ",
a(href = "https://ijeamaka-anyene.netlify.app/",
class = "artist-link",
style = "font-size: 16px",
"Ijeamaka Anyene")),
p("The source code can be found on ",
a(href = "https://github.com/Ijeamakaanyene/rtistry_gallery",
class = "artist-link",
style = "font-size: 16px",
"Github")),
p("The design for this app was inspired by ",
a(href = "https://spoke-art.com/",
class = "artist-link",
style = "font-size: 16px",
"Spoke-Art gallery")),
p("The art gallery logo was created by ",
a(href = "https://twitter.com/allison_horst",
class = "artist-link",
style = "font-size: 16px",
"Allison Horst")),
p("Art brush loading icon is by Fernando Vasconcelos from the Noun Project")
)
)
)
)
)
server = function(input, output, session) {
#### Collections
# Filter the data
filtered_tweet_data = reactive({
if(input$collections_filter == "All"){
tweet_data
} else {
tweet_data %>%
filter(username == input$collections_filter)
}
})
# Reduce dataset to page selected
output_tweet_data = reactive({
filtered_tweet_data() %>%
slice(input$pager$page_current)
})
# Triggers when clicks tabpanel collections and when filtered
# Also this section is 100% from wleepang/shiny-pager-ui example
observeEvent(
eventExpr = {
c(input$collections, input$collections_filter)
},
handlerExpr = {
# Updates pages total to filtered data
pages_total = nrow(filtered_tweet_data())
page_current = input$pager$page_current
if (input$pager$page_current > pages_total) {
page_current = pages_total
}
updatePageruiInput(
session, 'pager',
page_current = page_current,
pages_total = pages_total
)
}
)
# Creates the output of the tweet
output$tweet = renderUI({
output_tweet_data() %>%
purrr::pmap(create_tweet_card)
})
### FEATURED ARTISTS
# creates the output of the artist card
output$artist_card = renderUI({
username_info %>%
arrange(!!rlang::sym(input$artist_filter)) %>%
select(-username) %>%
purrr::pmap(create_artist_card)
})
}
shinyApp(ui, server)