我尝试将我的R Shinyapp与HTML模板一起使用,如下所示:
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中的代码是错误的?
发布于 2020-07-22 12:28:25
这就解决了这个问题:)
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)
https://stackoverflow.com/questions/63032329
复制相似问题