Not sure if you're running shiny-server or not... so i'm going to provide a solution that doesn't include editing anny configuration files. This worked on both local(win7x64) and linux(ubuntu)...
All I really did was base64
encode the file, and pass that to the html-tag.
app.audio <- function(url = NULL, ...){
https_url <-
'https://upload.wikimedia.org/wikipedia/commons/8/87/Jazz_Trombone.ogg'
local_path <- "inst/www/Jazz_Trombone.ogg"
as_b64 <- markdown:::.b64EncodeFile(local_path)
ui <- fluidPage(
column(4, tags$h4('https via url'),
tags$audio(
controls = "controls",
tags$source(
src = https_url,
type='audio/ogg; codecs=vorbis')
)),
column(4, tags$h4('via local_path'),
tags$audio(
controls = "controls",
tags$source(
src = local_path,
type='audio/ogg; codecs=vorbis')
)),
column(4, tags$h4("via base 64 encoding"),
tags$audio(
controls = "controls",
tags$source(
src = as_b64,
type='audio/ogg; codecs=vorbis')
))
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
}
Which results in:
> app.audio()
So the local path isn't working, although check out ?shiny::addResourcePath
for setting a valid global path in-app; that might work also.
Edit
Was able to get each attempt working with full functionality of controls... ran locally on windows to mimic your setup and adding the resource path seemed to fix all the issues.
app.audio <- function(url = NULL, ...){
# Instruct shiny to add this resource path so we can call/source files from
# the /inst/www with only www
addResourcePath(prefix = "www", "./inst/www")
https_url <-
'https://upload.wikimedia.org/wikipedia/commons/8/87/Jazz_Trombone.ogg'
local_path <- "inst/www/Jazz_Trombone.ogg"
as_b64 <- markdown:::.b64EncodeFile(local_path)
ui <- fluidPage(
column(4, tags$h4('https via url'),
tags$audio(
controls = "controls",
tags$source(
src = https_url,
type='audio/ogg; codecs=vorbis')
)),
column(4, style="background:#F5F5F5", tags$h4('via local_path'),
fluidRow(tags$h5("using htmltools::tag"),
tags$audio(
controls = "controls",
tags$source(
src = "www/Jazz_Trombone.ogg", # changing to resource-path prefix
type='audio/ogg; codecs=vorbis')
)),
fluidRow(tags$h5("Using good-ole html"),
# Testing with straight up html
HTML(paste0(
c('<audio controls>',
' <source src="www/Jazz_Trombone.ogg" type="audio/ogg; codecs=vorbis">',
'</audio>'),
collapse = "\n")))),
column(4, tags$h4("via base 64 encoding"),
tags$audio(
controls = "controls",
tags$source(
src = as_b64,
type='audio/ogg; codecs=vorbis')
))
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
}
