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

夙愿已清 提交于 2019-12-22 10:35:21

问题


In Shiny, we have downloadButton() and fileInput() buttons for downloading and uploading data respectively.

However it happens that, with downloadButton() there is download icon, and however with fileInput() no icon is attached.

In my Shiny app, I have both buttons. However since one of them has icon attached, it brings some kind of visual inconsistency in my App.

So, I either want to remove such icon from downloadButton(), or add some upload button with fileInput() to bring consistency.

However, it appears that there is not any direct approach to perform either of them.

So can anybody suggest here if there is any way to :

Either remove icon from downloadButton() Or, attach some upload icon with fileInput()

Any pointer is highly appreciated.

Thanks,


回答1:


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){
  }
)



回答2:


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


来源:https://stackoverflow.com/questions/49350509/adding-removing-icon-in-downloadbutton-and-fileinput

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!