gpt4 book ai didi

css - 如何在 Shiny 中为 downloadButton 添加图标?

转载 作者:太空宇宙 更新时间:2023-11-04 06:11:12 28 4
gpt4 key购买 nike

我可以在 Shiny 的应用程序中将自己的图标添加到 downloadButtondownloadBttn (shinyWidgets) 吗?

downloadBttn("downloadDataxlsx",
label = "Download .xlsx",
style = "stretch",
color = "primary",
size = "md"))

最佳答案

> 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 中插入您想要的图标,然后使用与普通下载按钮一样的功能

使用方法:

#

# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#

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)

# Define UI for application that draws a histogram
ui <- fluidPage(

# Application title
titlePanel("Old Faithful Geyser Data"),

# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30),
customDownloadbutton("myDownloadButton")
),

# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)

# Define server logic required to draw a histogram
server <- function(input, output) {

output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)

# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}

# Run the application
shinyApp(ui = ui, server = server)

关于css - 如何在 Shiny 中为 downloadButton 添加图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56395192/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com