首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >R Shiny -将JS文件添加到HTML模板

R Shiny -将JS文件添加到HTML模板
EN

Stack Overflow用户
提问于 2020-07-22 10:39:48
回答 1查看 47关注 0票数 0

我尝试将我的R Shinyapp与HTML模板一起使用,如下所示:

代码语言:javascript
运行
AI代码解释
复制
library(shiny)

server <- function(input, output, session) {
##
}

ui <- function() {
  htmlTemplate("dist/index.html")
}

# Serve the files in the js folder
if (dir.exists("dist")) {
  addResourcePath("js", "dist")
}

shinyApp(ui, server)

当我在浏览器中打开index.html时,一切都可以正常工作,但并不是与shiny结合在一起。我的索引html中的js文件是这样链接的:<script src=js/chunk-vendors.b0f460c7.js>

我试图用addResourcePath添加一个资源路径,但是我不能让它工作。有谁知道怎么解决这个问题吗?我必须改变我在html中的路径,还是我在R中的代码是错误的?

EN

回答 1

Stack Overflow用户

发布于 2020-07-22 12:28:25

这就解决了这个问题:)

代码语言:javascript
运行
AI代码解释
复制
library(shiny)

server <- function(input, output, session) {
  histogramData <- reactive({
    req(input$bins)
    x <- faithful$waiting
    breaks <- round(seq(min(x), max(x), length.out = input$bins + 1), 1)
    dist <- hist(x, breaks = breaks, plot = FALSE)
    list(
      breaks = breaks,
      counts = dist$counts,
      ticks = pretty(breaks)
    )
  })
  
  observe({
    session$sendCustomMessage("histogramData", histogramData())
  })
}

ui <- function() {
  htmlTemplate("dist/index.html")
}

# Serve the bundle at js/main.js
if (dir.exists("dist/js")) {
  addResourcePath("js", "dist/js")
}

# Serve the bundle at js/main.js
if (dir.exists("dist/css")) {
  addResourcePath("css", "dist/css")
}

# Serve the bundle at js/main.js
if (dir.exists("dist/img")) {
  addResourcePath("img", "dist/img")
}


shinyApp(ui, server)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63032329

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文