#########
# Date: 4/6/21
# Author: JA
#########
pacman::p_load(
#dataframe
tidyverse,
#viz
plotly,
#webapps
shiny,
#api
spotifyr
)
# Authentication
# Authorization
readRenviron(".env")
# Dashboard
# Tablero
# (Graphical) User Interface
ui <- pageWithSidebar(
titlePanel("Hallazgos Musicales"),
sidebarPanel(
selectInput(
inputId="a",
label="Artista A:",
choices=c("The XX","Billie Eilish","Adele","The Killers"),
selected="The XX"
),
selectInput(
inputId="b",
label="Artista B:",
choices=c("Willie Colón","Bad Bunny","J Balvin","Buena Vista Social Club"),
selected="Buena Vista Social Club"
),
selectInput(
inputId="x",
label="X:",
choices=c("valence","danceability","instrumentalness","key_name"),
selected="valence"
),
selectInput(
inputId="y",
label="Y:",
choices=c("valence","danceability","instrumentalness","key_name"),
selected="key_name"
),
),
mainPanel(
plotlyOutput(
outputId="plot"
)
)
)
# Server
# Reactivity
server <- function(input,output) {
access_token <- reactive({
get_spotify_access_token(
client_id=Sys.getenv("SPOTIFY_CLIENT_ID"),
client_secret=Sys.getenv("SPOTIFY_CLIENT_SECRET")
)
})
a <- reactive({
get_artist_audio_features(
artist=input$a,
authorization=access_token()
)
})
b <- reactive({
get_artist_audio_features(
artist=input$b,
authorization=access_token()
)
})
x <- reactive({
input$x
})
y <- reactive({
input$y
})
output$plot <- renderPlotly({
plot <- ggplot() +
geom_point(a(),mapping=aes_string(x=x(),y=y()),color="blue") +
geom_point(b(),mapping=aes_string(x=x(),y=y()),color="red")
ggplotly(plot)
})
}
shinyApp(ui,server)
# killers <- get_artist_audio_features(
# artist="The Killers",
# authorization=access_token
# )
#
# willie <- get_artist_audio_features(
# artist="Willie Colón",
# authorization=access_token
# )
#
# ggplot() +
# geom_point(willie,mapping=aes(x=valence,y=key_name),color="red") +
# geom_point(killers,mapping=aes(x=valence,y=key_name),color="blue")
Comments
0 B
|0 👍
/0 👎
0 B
|👍
/👎