每行 DT 数据 table 中的操作按钮中未显示垃圾图标
Trash Icon not showing in action button in DT data table in every row
我已经在数据 table 的每一行中添加了一个操作按钮,但是,图标没有显示在 table 中。只有按钮。
library(shiny)
library(tidyverse)
library(DT)
# Define UI for application that draws a histogram
ui <- fluidPage(
DT::DTOutput(outputId = "dt_table")
)
x <- 1:32 %>%
purrr::map_chr(~paste0(
'<button class="btn btn-default action-button btn-danger" id="',
.x, '" type="button"><i class="fa fa-trash-alt"></i></button>'
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$dt_table <- DT::renderDT({
mtcars %>%
dplyr::bind_cols(tibble("x"= x))
}, escape = F)
}
# Run the application
shinyApp(ui = ui, server = server)
那是因为您的图标需要 fontawesome 库。要包含它,您可以使用 icon
函数在您的应用中的某处添加一个图标,然后将其隐藏:
ui <- fluidPage(
div(style = "display: none;", icon("refresh")),
......
否则,您可以使用 glyphicon 图标。这些与 bootstrap 库一起使用,它始终包含在 Shiny 应用程序中。
我已经在数据 table 的每一行中添加了一个操作按钮,但是,图标没有显示在 table 中。只有按钮。
library(shiny)
library(tidyverse)
library(DT)
# Define UI for application that draws a histogram
ui <- fluidPage(
DT::DTOutput(outputId = "dt_table")
)
x <- 1:32 %>%
purrr::map_chr(~paste0(
'<button class="btn btn-default action-button btn-danger" id="',
.x, '" type="button"><i class="fa fa-trash-alt"></i></button>'
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$dt_table <- DT::renderDT({
mtcars %>%
dplyr::bind_cols(tibble("x"= x))
}, escape = F)
}
# Run the application
shinyApp(ui = ui, server = server)
那是因为您的图标需要 fontawesome 库。要包含它,您可以使用 icon
函数在您的应用中的某处添加一个图标,然后将其隐藏:
ui <- fluidPage(
div(style = "display: none;", icon("refresh")),
......
否则,您可以使用 glyphicon 图标。这些与 bootstrap 库一起使用,它始终包含在 Shiny 应用程序中。