How to embed Spotify Artists, Playlist, or Album and Media Player in Shiny App

Hello,

I want to embed a Spotify Artist into a Shiny app that I am building. I have copied the artist's embed code from Spotify as shown below:

<iframe style="border-radius:12px" src="https://open.spotify.com/embed/artist/3RwQ26hR2tJtA8F9p2n7jG?utm_source=generator" width="100%" height="380" frameBorder="0" allowfullscreen="" allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture" loading="lazy"></iframe>

Now, I tried to embed it in my shiny app with the code below:

library(shiny)

ui <- navbarPage(title = "Player",
tabPanel(id = "tab",title = strong("The Temptations"),icon = icon("info-circle"),
                          sidebarLayout(mainPanel(tags$iframe(style="border-radius:12px", src="https://open.spotify.com/embed/artist/3RwQ26hR2tJtA8F9p2n7jG?utm_source=generator", width="100%", height="380", frameBorder="0", allowfullscreen="", allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture", loading="lazy"))))),

server <- function(input,output,session){}

shinyApp(ui,server)

I am using the tags$iframe() function inside shiny to embed the artist. However, nothing displays in the app:

Please, any suggestions or advice will be greatly appreciated from anyone who has successfully embedded a Spotify player inside a shiny app. Thanks in anticipation of your help.

I was able to get your code to work by making the two changes below (commented in code).

  • changed icon("info-circle") to icon("circle-info")
  • within the sidebarLayout, I added sidebarPanel = '' as the first argument before mainPanel
library(shiny)

ui <- navbarPage(title = "Player",
                 tabPanel(id = "tab",
                          title = strong("The Temptations"),
                          icon = icon("circle-info"),  # updated
                          sidebarLayout(
                            sidebarPanel = '',  # updated
                            mainPanel(
                              tags$iframe(
                                style="border-radius:12px", 
                                src="https://open.spotify.com/embed/artist/3RwQ26hR2tJtA8F9p2n7jG?utm_source=generator", 
                                width="100%", 
                                height="380", 
                                frameBorder="0", 
                                allowfullscreen="", 
                                allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture", 
                                loading="lazy")
                              )
                            )
                          )
                 )

server <- function(input,output,session){}

shinyApp(ui,server)

Here is the result.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.