r 闪亮无法解析 HTML

rShiny failing to parse HTML

考虑以下应用:

library(shiny)
library(shinydashboard)
library(shinyWidgets)

tab_example <-
  tabItem(tabName = "example",
          fluidRow(
            column(6,
                   h4("example"),
                   includeHTML("example.html")
            )
          )
  )

body <-
  dashboardBody(
    tabItems(
      tab_example
    )
  )

sidebar <-
  dashboardSidebar(
    sidebarMenu(
      menuItem("Example", tabName = "example", icon = icon("bullseye"))
    )
  )

ui <-
  dashboardPage(
    dashboardHeader(title = "EXAMPLE"),
    sidebar,
    body
  )

server <- function(input, output) {


}

shinyApp(ui = ui, server = server)

其中example.html

<p>My first paragraph.</p>

这会正常运行,但是当 运行 一个更复杂的具有文件夹结构的示例时,它无法解析。

文件夹结构:

├── example
│   └── example.html
├── dashboard.R
├── ui_elements
│   └── sidebar.R
│   └── body.R
│   └── tabs
│    └── tab_example.R

tab_example.R:

source("example/example.html")

tab_example <-
  tabItem(tabName = "example",
          fluidRow(
            column(6,
                   includeHTML("example.html")
            )
          )
  )

错误信息是:

 Error in source("example/example.html") : 
  example/example.html:1:1: unexpected '<'
1: <

我在source("example/example.html")通话中有什么需要做的吗?

查看来自 source 的帮助,header 说:

Read R Code from a File, a Connection or Expressions

但是,您尝试读取 HTML 文件,因此失败。您可以在 includeHTML:

中指定正确的路径
includeHTML("example/example.html")

并且不需要使用 source