Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在闪亮的仪表板标题中添加downloadButton_Javascript_R_Shiny_Shinydashboard - Fatal编程技术网

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")



)