Re: [shinyapps-users] audio element in Shiny

25 views
Skip to first unread message

Tareef Kawaf

unread,
Sep 19, 2014, 8:52:55 AM9/19/14
to Andrew Caines, shinyap...@googlegroups.com
Hi Andrew,
Have you looked at the javascript console to see if you are getting any errors there?  I am guessing that it is not finding the audio file, and if that is the case, it is possible (I haven't played with it myself) that you need the audio file in the www directory.

Tareef


On Fri, Sep 19, 2014 at 11:33 AM, Andrew Caines <cain...@gmail.com> wrote:
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

--
You received this message because you are subscribed to the Google Groups "ShinyApps Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shinyapps-use...@googlegroups.com.
To post to this group, send email to shinyap...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shinyapps-users/0df295a4-12c5-4945-9b05-db5c90fb8c67%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yihui Xie

unread,
Sep 19, 2014, 4:35:49 PM9/19/14
to Tareef Kawaf, Andrew Caines, shinyap...@googlegroups.com, Garrett Grolemund
That is also my guess. Files under the root directory of the app will
not be found by direct links, which might be a little surprising... In
shiny, you can put files under www/ and link to them without the www
prefix, e.g. for an app with files

ui.R
server.R
www/foo.wav
bar.wav

You can link to foo.wav by tags$a(href = 'foo.wav', 'foo') (or
tags$audio(src = 'foo.wav')) but tags$a(href = 'bar.wav') will not
work by default, unless you used shiny::addResourcePath().

Anyway, when something does not work, you first see if there are error
messages in the R console, then Ctrl + Shift + J in Google Chrome to
see if there are error messages in the browser console. For apps
deployed to ShinyApps.io, shinyapps::showLogs() is what might help
you. (To Garret: we probably should add these common techniques for
diagnosing shiny apps to
http://shiny.rstudio.com/articles/debugging.html)

Regards,
Yihui
--
Yihui Xie <xiey...@gmail.com>
Web: http://yihui.name

Andrew Caines

unread,
Sep 19, 2014, 5:56:28 PM9/19/14
to shinyap...@googlegroups.com, tar...@rstudio.com, cain...@gmail.com, gar...@rstudio.com
Thanks Both for your help; yes I'd tried www before without success, but hadn't tried without the "www/" prefix -- that made it work! [I double-checked just now and the "www/" prefix breaks it .. not sure if that's expected behaviour]
Thanks also for the tip about checking the javascript console in future :-)
Reply all
Reply to author
Forward
0 new messages