问题
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