链接到RMarkdown上的本地html文件
我有一个带有shinny的交互式RMarkdown文档(即YAML标题中的行链接到RMarkdown上的本地html文件,html,r,shiny,r-markdown,shiny-server,Html,R,Shiny,R Markdown,Shiny Server,我有一个带有shinny的交互式RMarkdown文档(即YAML标题中的行runtime:shinny),我想在其中创建一个指向本地html文件的链接。但到目前为止,我试过的都不管用 在本例中,假设我的工作目录中有以下文件: 工作主任/ rmarkdown\U带有光泽。Rmd 闪亮的应用程序 www/ my_file.html 我想做的是在rmarkdown_内创建一个链接,该链接带有_shinny.Rmd,单击时会打开文件www/my_file.html 文件rmarkdown_
runtime:shinny
),我想在其中创建一个指向本地html文件的链接。但到目前为止,我试过的都不管用
在本例中,假设我的工作目录中有以下文件:
- 工作主任/
- rmarkdown\U带有光泽。Rmd
- 闪亮的应用程序
- www/
- my_file.html
---
title: "Rmarkdown with shiny"
output: html_document
runtime: shiny
---
[link_1](www/my_file.html)
[link_2](my_file.html)
[link_3](file://www/my_file.html)
```{r shiny_links, echo=F, eval=T}
renderUI(tags$a("link_4", href="my_file.html", target="_blank"))
renderUI(tags$a("link_5", href="www/my_file.html", target="_blank"))
renderUI(tags$a("link_6", href="file://www/my_file.html", target="_blank"))
shinyAppFile("shiny_app.R")
```
最后一行shinyAppFile(“shinny_app.R”)
我可以嵌入一个包含工作链接的应用程序(当应用程序单独运行时),但一旦嵌入它就不再工作了。这是Shining_app.R中的代码:
库(‘闪亮’)
ui基本上,当我们运行闪亮应用程序时,www
文件夹的内容是内部嵌入的,我们不需要在href
属性中包含www
文件夹。
但是,如果我们想通过runtime:shinny
来“公开”这些内容,我们需要添加shinny::addResourcePath()
并指定其文件夹:
---
title: "Rmarkdown with shiny"
output: html_document
runtime: shiny
---
```{r setup, include = FALSE}
library(knitr)
library(shiny)
library(here)
shiny::addResourcePath(prefix = "www", directoryPath = here::here("www"))
```
Relative File Path: [My HTML file](www/my_file.html)
Relative File Path: <a href = "www/my_file.html" target="_blank">My HTML file</a>
Absolute File Path: <a href = "http://www.shinyapps.io/" target="_blank">shinyapps.io</a>
Relative File Path:
```{r shiny-relative-links, echo = FALSE, eval = TRUE}
tags$a(href = "www/my_file.html",
tags$span(style = "color: #03a9f4", "My HTML file"),
target = "_blank")
```
Absolute File Path:
```{r shiny-absolute-links, echo = FALSE, eval = TRUE}
tags$a(href = "http://www.shinyapps.io/",
tags$span(style = "color: #03a9f4", "shinyapps.io"),
target = "_blank")
```
---
标题:“Rmarkdown与闪亮”
输出:html\u文档
运行时间:闪亮
---
```{r设置,include=FALSE}
图书馆(knitr)
图书馆(闪亮)
图书馆(这里)
Shinny::addResourcePath(prefix=“www”,directoryPath=here::here(“www”))
```
相对文件路径:[我的HTML文件](www/My_File.HTML)
相对文件路径:
绝对文件路径:
相对文件路径:
```{r相对链接,echo=FALSE,eval=TRUE}
标记$a(href=“www/my_file.html”,
标记$span(style=“color:#03a9f4”,“我的HTML文件”),
target=“_blank”)
```
绝对文件路径:
```{r绝对链接,echo=FALSE,eval=TRUE}
标签$a(href=”http://www.shinyapps.io/",
标签$span(style=“color:#03a9f4”,“shinyapps.io”),
target=“_blank”)
```
有关原始解决方案和讨论,请参阅。另外,.我知道您说该文件名为rmarkdown\u,带有_shinny.Rmd
,但我只想检查它是否绝对正确。当文件名包含空格时,我在runtime:shinny
中遇到了一些奇怪的行为。因此,我的建议是确保文件名中没有空格或非ascii字符。是的,文件名只包含字母和下划线,它正好是rmarkdown_with_shinny.Rmd
。没有空格或非ascii字符。
---
title: "Rmarkdown with shiny"
output: html_document
runtime: shiny
---
```{r setup, include = FALSE}
library(knitr)
library(shiny)
library(here)
shiny::addResourcePath(prefix = "www", directoryPath = here::here("www"))
```
Relative File Path: [My HTML file](www/my_file.html)
Relative File Path: <a href = "www/my_file.html" target="_blank">My HTML file</a>
Absolute File Path: <a href = "http://www.shinyapps.io/" target="_blank">shinyapps.io</a>
Relative File Path:
```{r shiny-relative-links, echo = FALSE, eval = TRUE}
tags$a(href = "www/my_file.html",
tags$span(style = "color: #03a9f4", "My HTML file"),
target = "_blank")
```
Absolute File Path:
```{r shiny-absolute-links, echo = FALSE, eval = TRUE}
tags$a(href = "http://www.shinyapps.io/",
tags$span(style = "color: #03a9f4", "shinyapps.io"),
target = "_blank")
```