首页 > 解决方案 > R string replacing part of javascript

问题描述

I'm sure this is a noob question but I couldn't figure out how you would insert a R string object inside a javascript. For example,

trackname <- "audiotrack1"

into

tag$script(var url = 'audioResources/' + trackname + '.wav')

Where I would want to replace the "trackname" with "audiotrack1". I'm sure paste0 isn't the best way to do this. What is the standard way to go about doing this?

Many thanks.

标签: javascriptrshinyshinyjs

解决方案


This is not correct. You can do:

tags$script(HTML(sprintf("var url = 'audioResources/%s.wav'", trackname)))

推荐阅读