audio element in Shiny

3,291 views
Skip to first unread message

Andrew Caines

unread,
Sep 19, 2014, 6:35:25 AM9/19/14
to shiny-...@googlegroups.com
Hello All,

I'd like to play a sound file in my Shiny app and so I've used the tags$audio() function as described here: http://shiny.rstudio.com/articles/tag-glossary.html

In my browser, the controls render ok (therefore I know the function is recognised), but the audio is not found (i.e. nothing plays). The audio file is in the same directory as the server.R and ui.R files (and I've tried moving it to a subdir) and plays fine in general media applications. It's a WAV but I've also tried MP3. I'm using Chrome on Mac Mavericks and have also tried Firefox and Safari.

Here's the line of code I'm using. Does anyone have experience of this issue, or know what could be the cause?

tags$audio(src = "audio.wav", type = "audio/wav", autoplay = NA, controls = NA)

many thanks, Andrew

Andrew Caines

unread,
Mar 11, 2015, 5:16:49 PM3/11/15
to shiny-...@googlegroups.com
A quick update as I realised I worked this one out but didn't post the answer:
- it's simply that the audio file needs to be in a 'www' subdirectory, but no need to refer to this in the 'src' filepath.
- i.e. leave the line as it is in the example below, but make sure "audio.wav" is in a "www" dir.

Richa Jha

unread,
May 25, 2016, 2:48:03 AM5/25/16
to Shiny - Web Framework for R
Hi Andrew, I am still not able to play the file in shiny dashboard.
Is there any other issue that i might be facing. I have an audio(wav) file in the same directory where my ui and server files are present. I tried making another subdirectory and saved the audio files in there. Still it is not playing. Do I need to add something in server.R for this to play? Please help!(in dire need of help)

Richa Jha

unread,
May 26, 2016, 2:34:50 AM5/26/16
to Shiny - Web Framework for R
Hi Andrew, I could play the audio file now.
One more concern is that I have to make the audio file reactive. As and when the text on the shiny dashboard changes, the audio should change as well. Now when I am trying to read the reactive text, the error coming is " The server is responding slowly. Please try again later". Can you provide any insights for this? Please help!
Reply all
Reply to author
Forward
0 new messages