This repository was archived by the owner on Feb 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.R
More file actions
48 lines (41 loc) · 1.3 KB
/
server.R
File metadata and controls
48 lines (41 loc) · 1.3 KB
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
shinyServer(function(input, output) {
### Sidebar content
observeEvent(input$submit, {
checkpoint1$out <- tryCatch({
gen_song_url(input$artistname, input$songname) %>%
read_html()
},
error=function(w){"fail"})
if (!is.character(checkpoint1$out)){
user$artistname <- input$artistname
user$songname <- input$songname
}
})
output$cover_art <- renderImage({
if (is.character(checkpoint1$out)){
return(list(src="./images/fail.png", contentType="image/png", alt="Song not found"))
} else {
img <- gen_song_url(artist=user$artistname, song=user$songname) %>%
read_html() %>%
html_nodes(css="img") %>%
purrr::pluck(1) %>%
html_attr("src") %>%
image_read(density=500, depth=16, strip=TRUE) %>%
image_resize("x235") %>%
image_write(tempfile(fileext=".png"), format="png")
return(list(src=img, contentType="image/png", alt="Album Cover Art"))
}
}, deleteFile=FALSE)
###
### Tab 1 content
output$lyric_table <- DT::renderDataTable({
get_lyric_data() %>%
DT::datatable(style="bootstrap", options=list(dom="tp"))
})
###
### Tab 2 content
output$graph <- renderPlot({
create_graph()
}, width=700, height=750)
###
})