HTML(或R Shiny)音频缓存 [英] HTML (or R Shiny) Audio Caching

查看:120
本文介绍了HTML(或R Shiny)音频缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在弄清楚如何制作一个Shiny服务器播放wav文件后,我创建了一个闪亮的服务器,动态创建基于反应输入的wav文件。但是,第一个wav文件被缓存,尽管文件发生了变化甚至重命名文件,但只有第一个wav被播放,直到整个页面刷新。



怎么可能我通过基于HTML的Shiny应用程序更改了改变后的wav文件?



我知道这个问题已经被HTML开发者问及几个地方,使用 JavaScript jquery / php 服务器端解决方案,但我还没有弄清楚如何制作任何这些工作与闪亮。

解决方案

解决由BSU教授。冠军。在脚本的顶部,我们有一些名称处理函数用于保持wav名称的唯一性,然后是一个获取适当音频标签的函数:

  get_audio_tag <-function(filename){tags $ audio(src = filename,
type =audio / wav,controls = NA)}
wave_name< -function(n,p1, (粘贴(sound,num,n,w1,p1,f1,w2,p2,f2,w3)f1,p2,f2,p3,f3, ,p3,f3,lev,
gsub(\\\。,_,l),sep =_),.wav)
}

诀窍是变量 wavname 的输出功能,以便每次触摸无功输入时,wav文件都会更改名称。然后, get_audio_tag 函数也在输出函数中运行,以便进行更新。输出函数的代码如下所示:

  wname <-wave_name(输入$ radio,
输入$ frequency1,输入$ form1,
input $ frequency2,input $ form2,
input $ frequency3,input $ form3,
input $ level)

output $ audiotag< -renderUI get_audio_tag(tempwav.wav))#启动波形文件
输出$ audiotag< -renderUI(get_audio_tag(wavname))

启动tempwav是必要的,因为音频标签在反应元素发送其第一个输出之前先加载到HTML中。

After figuring out how to make a Shiny server play a wav file, I created a shiny server that dynamically creates wav files based on reactive input. However, the first wav file gets cached, and despite changes to the file or even renaming the file, only the first wav is played until a full page refresh.

How could I play a changed wav file after it is changed through an HTML-based Shiny app?

I understand that this question has been asked (and solved) for HTML developers in a few places, using javascript or Jquery/php or a server-side solution, but I haven't figured out how to make any of these work with Shiny.

解决方案

Solved by BSU prof. Champion. At the top of the script we have some name handling functions for keeping the wav names unique, and then a function that gets the appropriate audio tag:

    get_audio_tag<-function(filename){tags$audio(src = filename,
                                  type ="audio/wav", controls = NA)}
    wave_name<-function(n,p1,f1,p2,f2,p3,f3,l){
    paste0( paste("sound","num",n, "w1",p1,f1,"w2", p2,f2,"w3",p3,f3,"lev",
    gsub("\\.","_",l), sep="_"), ".wav")
    }

The trick is that the variable wavname updates dynamically inside one of the output functions, so that every time a reactive input is touched, the wav file changes names. Then the get_audio_tag function runs inside the output function as well so that the update occurs. The code the output function looks like:

wname<-wave_name(   input$radio,
                    input$frequency1,input$form1, 
                    input$frequency2,input$form2,
                    input$frequency3,input$form3,
                    input$level)

output$audiotag<-renderUI(get_audio_tag("tempwav.wav")) #starting wave file    
output$audiotag<-renderUI(get_audio_tag(wavname))

The starting tempwav is necessary because the audio tags are loaded in the HTML before the reactive elements send their first output.

这篇关于HTML(或R Shiny)音频缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆