Skip to content Skip to sidebar Skip to footer

Including Js/css Scripts In Shiny App

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.com

Solution 1:

For 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.com/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
  }
}

Solution 2:

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'))

Post a Comment for "Including Js/css Scripts In Shiny App"