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

前端 未结 1 1811
栀梦
栀梦 2021-01-14 17:46

How can I include a remote JS file in my app using shinydashboard? I know there is the includeScript function. I tried

...

# using shiny dashbo         


        
相关标签:
1条回答
  • 2021-01-14 18:13

    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) {
      }
    ))
    
    0 讨论(0)
提交回复
热议问题