Javascript 如何在闪亮的仪表板标题中添加downloadButton
我想在我的Javascript 如何在闪亮的仪表板标题中添加downloadButton,javascript,r,shiny,shinydashboard,Javascript,R,Shiny,Shinydashboard,我想在我的闪亮仪表板上有一个下载按钮,该按钮可以下载www文件夹中的.pdf文件,该文件解释了如何使用仪表板 到目前为止,我已经成功地添加了一个主页按钮和一个GitHub链接(window.open),但我找不到实现下载按钮的方法 到目前为止,我的代码如下: 标题R: header这是来自另一个论坛,有人问了同样的问题。这对那个人起了作用 > downloadButton function (outputId, label = "Download", class = NULL
闪亮仪表板上有一个下载按钮
,该按钮可以下载www文件夹中的.pdf文件,该文件解释了如何使用仪表板
到目前为止,我已经成功地添加了一个主页按钮
和一个GitHub
链接(window.open),但我找不到实现下载按钮
的方法
到目前为止,我的代码如下:
标题R:
header这是来自另一个论坛,有人问了同样的问题。这对那个人起了作用
> downloadButton
function (outputId, label = "Download", class = NULL, ...)
{
aTag <- tags$a(id = outputId, class = paste("btn btn-default shiny-download-link",
class), href = "", target = "_blank", download = NA,
icon("download"), label, ...)
}
<bytecode: 0x000000001a919c58>
<environment: namespace:shiny>
您可以通过为下载按钮添加另一个标签
(假设您的pdf文件保存在www
文件夹下名为img
的子文件夹下)来完成此操作
因此,在现有标题代码之后附加:
header <- dashboardHeader(title = "Support Vector Machine - Credit Fraud",
titleWidth = 400,
tags$li(a(onclick = "onclick =window.open('https://github.com/xxx/xxx')",
href = NULL,
icon("github"),
title = "GitHub",
style = "cursor: pointer;"),
class = "dropdown"),
tags$li(a(onclick = "openTab('foa')",
href = NULL,
icon("home"),
title = "Homepage",
style = "cursor: pointer;"),
class = "dropdown",
tags$script(HTML("
var openTab = function(tabName){
$('a', $('.sidebar')).each(function() {
if(this.getAttribute('data-value') == tabName) {
this.click()
};
});
}"))),
## DOWNLOAD
tags$li(a(id = "download", class = "fa fa-download",
href = "/img/how_to.pdf", download = "how_to.pdf"),
class = "dropdown")
)
标题感谢您的回答。我想将下载按钮
放入仪表板的标题中。我得到以下错误:错误:预期标记的类型为li
。
customDownloadbutton <- function(outputId, label = "Download"){
tags$a(id = outputId, class = "btn btn-default shiny-download-link", href = "",
target = "_blank", download = NA, icon("accessible-icon"), label)
}
library(shiny)
ui <- fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30),
customDownloadbutton("myDownloadButton")
),
mainPanel(
plotOutput("distPlot")
)
tags$li(a(id = "download", class = "fa fa-download",
href = "/img/how_to.pdf", download = "how_to.pdf"), class = "dropdown")
header <- dashboardHeader(title = "Support Vector Machine - Credit Fraud",
titleWidth = 400,
tags$li(a(onclick = "onclick =window.open('https://github.com/xxx/xxx')",
href = NULL,
icon("github"),
title = "GitHub",
style = "cursor: pointer;"),
class = "dropdown"),
tags$li(a(onclick = "openTab('foa')",
href = NULL,
icon("home"),
title = "Homepage",
style = "cursor: pointer;"),
class = "dropdown",
tags$script(HTML("
var openTab = function(tabName){
$('a', $('.sidebar')).each(function() {
if(this.getAttribute('data-value') == tabName) {
this.click()
};
});
}"))),
## DOWNLOAD
tags$li(a(id = "download", class = "fa fa-download",
href = "/img/how_to.pdf", download = "how_to.pdf"),
class = "dropdown")
)