0

I am working on a project, trying to render audio dynamically. That is, I can click a button and play a selected local audio.

I have read this post and tried zedii's trick. The problem remains still.

Well I build a test app as shown below.

library(shiny)
# test set ----
ui <- fluidPage(
  textInput('my_music','path:',value="questionF"),
  actionButton("ok", "Okay"),
  uiOutput('my_audio')
  # tags$audio(src = "questionF.mp3", type = "audio/mp3")
)

get_audio_tag <- function(filename) {
  tags$audio(src = filename,
             type = "audio/mp3",
             controls = "controls")
}

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

  # Render the audio player
  observeEvent(input$ok, {

    wav_name = input$my_music
    # output$my_audio <-renderUI(get_audio_tag("questionF.mp3"))
    output$my_audio <-renderUI(get_audio_tag(wav_name))

  })

}

shinyApp(ui = ui, server = server)

When I click the button, the first song turns out okay. But the following ones seemed pretty hard to load, for my computer would freeze with the memory used by Rstudio rising.

Any thoughts will be appreciated.


updates:

I tried on different browsers. These codes would failed on Chrome but works fine on Microsoft edges. Looks like a caching problem. So now my question is how can I make the codes work on every platform using shiny/R?


My codes works on most browser other than Chrome. I think it's more like a Chrome's problem.

J.Li
  • 61
  • 6
  • I tried your code and played two different mp3 songs, everything works fine. Maybe is a problem in mp3. file? – Miha Mar 02 '19 at 11:16
  • Thank you. I tried again on different browser. Turns out on Microsoft Edges it works perfectly but fail on Chrome. Looks like it's because of differernt caching strategies? – J.Li Mar 02 '19 at 12:31

0 Answers0