How to include a remote JavaScript file in a shiny dashboard app?

这一生的挚爱 提交于 2019-12-01 09:21:36

You can include remote JS files using the src argument of a script tag

library(shiny)
jsfile <- "https://gist.githack.com/daattali/7519b627cb9a3c5cebcb/raw/91e8c041d8fe4010c01fe974c6a35d6dd465f92f/jstest.js"

runApp(shinyApp(
  ui = fluidPage(
    tags$head(tags$script(src = jsfile))
  ),
  server = function(input, output) {
  }
))

EDIT: Ok, so you want this to work with a shinydashboard. It makes sense why your way doesn't work. Look at the documentation for dashboardPage. The first argument is header. You can't just start providing tags/UI elements you want to include. The includescript or any other such elements should go inside the dashboardBody. For example

library(shiny)
library(shinydashboard)
jsfile <- "https://gist.githack.com/daattali/7519b627cb9a3c5cebcb/raw/91e8c041d8fe4010c01fe974c6a35d6dd465f92f/jstest.js"

runApp(shinyApp(
  ui = dashboardPage(
    header = dashboardHeader(),
    sidebar = dashboardSidebar(),
    body = dashboardBody(
      tags$head(tags$script(src = jsfile))
    )
  ),
  server = function(input, output) {
  }
))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!