I have made progress - I have gotten it to work in this example with the following code, but the problem is that when I put it in my app it doesn't work, and the only thing that has to be changed is that now the code that converts the file to .wav has to be reactive and the code that saves it to the file must use observe() so that it automatically completes the task, it isn't lazy like reactive({}), it must become:
Soundwav <- reactive({
Wave(left = Soundfile(), samp.rate = 44100, bit = 32)
})
observe(
savewav(Soundwav(), filename = "www/Soundwavexported.wav")
)
And suddenly it stops working again. I checked to see if it is because when I use read_csv it imports as a data frame, and when it is in the main app it is a numeric, but the package says that it supports numerics.
Here is my solution for the example:
library(shiny)
library(shinydashboard)
library(readr)
library(tuneR)
library(seewave)
Soundfile <- read_csv("Soundfile.csv")
class(Soundfile)
ui <- dashboardPage(
dashboardHeader(title = "Example Audio Play"),
dashboardSidebar(
sidebarMenu(
menuItem("Play Audio", tabName = "playaudio", icon = icon("dashboard"))
)),
dashboardBody(
tabItems(
tabItem(tabName = "playaudio",
fluidRow(
box(title = "Controls", width = 4,
actionButton("playsound", label = "Play The Rebuilt Sound!"))
)
)
)
)
)
server <- function(input, output) {
Soundwav <- Wave(left = Soundfile, samp.rate = 44100, bit = 16)
savewav(Soundwav, filename = "www\\Soundwavexported.wav")
observeEvent(input$playsound, {
insertUI(selector = "#playsound",
where = "afterEnd",
ui = tags$audio(src = "Soundwavexported.wav", type = "audio/wav", autoplay = NA, controls = NA, style="display:none;")
)
})
}
shinyApp(ui, server)
Thanks!