mat*_*jay 3 r shiny shinydashboard
如何使用shinydashboard在我的应用程序中包含远程JS文件?我知道有这个includeScript功能.我试过了
...
# using shiny dashboard
ui <- dashboardPage(
includeScript("http://the.path.to/my/js-file.js")
dashboardHeader(
title = "My title",
titleWidth = 400
),
...
Run Code Online (Sandbox Code Playgroud)
这会导致错误:
Error in tagAssert(header, type = "header", class = "main-header") :
Expected tag to be of type header
Run Code Online (Sandbox Code Playgroud)
我试图将调用放在其他地方,将其与其结合tags$head,在本地存储JS文件并使用本地路径引用加载它,但无济于事.
所以我坚持以下问题?
includeScript远程资源的路径吗?@daattali已经提出了一个解决方案,用于纯粹的基于Shiny的实现(没有shinydashboard)使用tags$head,但这似乎不适用于shinydashboard.
您可以使用标记的src参数包含远程JS文件script
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) {
}
))
Run Code Online (Sandbox Code Playgroud)
编辑:好的,所以你希望这与shinydashboard一起工作.你的方式不起作用是有道理的.查看文档dashboardPage.第一个论点是header.您不能只是开始提供要包含的标签/ UI元素.包含脚本或任何其他此类元素应该进入仪表板体内.例如
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) {
}
))
Run Code Online (Sandbox Code Playgroud)