r - R Shiny - 在新选项卡中打开可下载文件
问题描述
我正在使用 R Shiny 的 downloadHandler/downloadLink 函数来制作一个可供下载的 html 文件。根据默认行为,文件由浏览器下载到系统。但是,由于我要下载的文件是 HTML 文件 (.html),有没有办法直接在新的浏览器选项卡中打开文件,而不是将文件下载到系统?
我在 StackOverflow 上发现了一个类似的问题,建议添加target = "_blank"。但是,即使这对我也不起作用。
我的 R 代码:
# UI Code:
ui <- fluidPage(
includeCSS("custom.css"),
div(class = "intro-divider"),
tags$style(".logo {
margin-left: 10px;
}"),
tags$div(class="logo", img(src="logo.gif", height='50px',width='350px')),
br(),
div(class = "intro-divider"),
br(),
h3("Title Page"),
wellPanel(
tags$head(tags$style(type = "text/css", '.well{width: 600px}')),
h4("July 20, 2018"),
tags$div(
tags$ul(
tags$li(downloadLink("july20_1", "Download HTML File", target = "_blank"))
)
)
)
)
# Server Code
server = function(input, output) {
output$july20_1 <- downloadHandler(
filename = "july20_analysis_html.html",
content = function(file) {
file.copy("july20_analysis_html.html", file)
})
}
# Run the application
shinyApp(ui = ui, server = server)
如何使文件直接在新选项卡中打开?
PS:我在谷歌 Chrome 浏览器上测试了这个应用程序。
解决方案
推荐阅读
- r - 在r中创建递归函数
- c# - Linq List 返回重复数据而不是多个数据集
- reactjs - 如何汇总根组件发送的道具
- python - statsmodels 的 MLEModel 类是否使用期望最大化进行拟合?
- azure - 当后端请求成功时,如何调试从 Azure API 管理到 Front Door 的 502 Bad Gateway 错误响应?
- pentaho - 如何让 XSL 3.0 与 Pentaho XSL Step 一起工作
- python - 将一个文件 Tkinter 条目分配给另一个文件 tkinter 条目
- react-native - 如何制作圆形倒计时/仪表以显示反应原生的剩余天数
- python - 使用 AutoSys 运行 python 脚本时出错
- terraform - 重用在terraform的父模块中声明和定义的变量