我想在自己的downloadButton
上添加一个shiny Dashboard
,以下载我在www文件夹中拥有的.pdf文件,以说明如何使用仪表板。
到目前为止,我已经成功添加了Home Button
和GitHub
链接(window.open),但是我找不到实现downloadButton
的方法。
到目前为止,这是我的代码:
header R:
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()
};
});
}")))
)
server.R:
server <- function(input, output, session) {
observeEvent(input$home, {
updateTabItems(session, "sidebar", "foa")
})
}
结果是:
我只想在
downloadButton
图标旁边添加一个GitHub
,上面写有“How to use this Dashboard”,当您单击它时,它将下载我的www文件夹中的.md或.pdf。 最佳答案
这是从另一个论坛有人也有同样的问题。这对那个人有用。
> 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>
这是“下载”按钮后面的功能。只需使用您自己的功能。
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)
}
只需在
icon
中插入所需的图标,然后使用正常的下载按钮等功能如何使用它:
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")
)