admin管理员组文章数量:1431456
I am building a Shiny application, but as it should get arguments for data for building plots, I decided to save my app as a function (using this tutorial: .html ).
Everything is working besides javascript and stylesheets that I would like to include (it was working earlier when I had standard structure: ui.R, server.R and included js/css files were in 'www' folder).
I tried to: - adding the files in the 'www' folder as before ([script.R, www folder: [style.css, script.js]]) - adding the files in separate folder, but in the same directory as the script launching the Shiny app ([script.R, scripts folder: [style.css, script.js]]) - adding the files in the same directory as my script launching the Shiny app ([script.R, style.css, script.js])
For including files I use code like: tags$head(tags$script(src="graph.js"))
Do you have any suggestions how to include scripts when you save your Shinny application as a function? Thanks in advance!
I am building a Shiny application, but as it should get arguments for data for building plots, I decided to save my app as a function (using this tutorial: http://shiny.rstudio./articles/function.html ).
Everything is working besides javascript and stylesheets that I would like to include (it was working earlier when I had standard structure: ui.R, server.R and included js/css files were in 'www' folder).
I tried to: - adding the files in the 'www' folder as before ([script.R, www folder: [style.css, script.js]]) - adding the files in separate folder, but in the same directory as the script launching the Shiny app ([script.R, scripts folder: [style.css, script.js]]) - adding the files in the same directory as my script launching the Shiny app ([script.R, style.css, script.js])
For including files I use code like: tags$head(tags$script(src="graph.js"))
Do you have any suggestions how to include scripts when you save your Shinny application as a function? Thanks in advance!
Share Improve this question asked Jul 22, 2014 at 8:05 pawluczukMpawluczukM 611 silver badge7 bronze badges2 Answers
Reset to default 3For anyone who may be having the same issue, I finally came up with the solution :-) There are 'include' functions in Shiny that let you specify a file with the absolute/relative path. Here is the reference: http://shiny.rstudio./reference/shiny/latest/include.html
And this is my example code:
app <- function(data)
{
shinyApp(
ui = fluidPage(
fluidRow(
# I created a 'www' folder that was included
# in the package that is launching Shiny app
tags$head(includeScript(system.file('www', 'script.js', package = 'myPackage'))),
tags$head(includeCSS(system.file('www', 'style.css', package = 'myPackage'))),
# some UI stuff
)
),
server = function(input, output, session) {
# some server stuff
}
}
This is now different. system.file
is not required for includeScript
So:
tags$head(includeScript(system.file('www', 'script.js', package =
'myPackage')))
Will be:
tags$head(includeScript('www/script.js', 'type' = 'text/javascript', 'data-unique-tag' = 'unique'))
本文标签: javascriptIncluding jscss scripts in Shiny appStack Overflow
版权声明:本文标题:javascript - Including jscss scripts in Shiny app - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745450809a2658874.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论