Adding/removing icon in downloadButton() and fileInput()

帅比萌擦擦* 提交于 2019-12-06 03:12:42

To add an icon to fileInput(), add a list to the buttonLabel. e.g.

shinyApp(
  fluidPage(
    fileInput("myFileInput",label="Test",buttonLabel=list(icon("folder"),"TestyMcTestFace"))
  ),
  function(input, output, session){
  }
)

If you look at the source code of downloadButton, you will see that changing/removing the button is pretty straightforward

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, ...)
## }
## <environment: namespace:shiny>

You just need to replace icon("download") with NULL. Here is a complete example

myDownloadButton <- function(outputId, label = "Download"){
  tags$a(id = outputId, class = "btn btn-default shiny-download-link", href = "", 
         target = "_blank", download = NA, NULL, label)
}

shinyApp(
  fluidPage(myDownloadButton("download")),
  function(input, output, session){
    output$download = downloadHandler(
      "file.rds", function(file){ saveRDS(mtcars, file) }
    )
  }
)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!