【发布时间】:2021-12-01 08:41:25
【问题描述】:
我正在尝试将按钮添加到 dabletable 中的列名,并在将鼠标悬停在该按钮上时添加 bsPopover。我可以在数据表之外成功创建弹出框和按钮,并且可以将按钮添加到数据表中。但是让弹出框在数据表中工作已被证明是不成功的。我选择“悬停”作为触发器,以便单击保留列排序功能。任何帮助或指导表示赞赏。请参阅下面的代表:
library(shiny)
library(shinyBS)
library(DT)
ui <- fluidPage(
titlePanel('Making a Popover Work in DataTable'),
mainPanel(
fluidRow(
#popover button
p(bsButton("workingPop",
label = "",
icon = icon("question"),
style = "info",
size = "extra-small")
),
#popover content
bsPopover(id = "workingPop", title = "This Popover Works",
content = "It works very well",
placement = "right",
trigger = "hover",
options = list(container = "body")
)),
fluidRow(dataTableOutput('myTable'),
bsPopover(id="notWorking", title = "This one does not work",
content = "I'd like to give information about hp: it means horsepower. I want a popover, because my real example has lot's of text.",
placement = "top",
trigger = "hover",
options = list(container = "body")))
)
)
server <- function(input, output, session) {
output$myTable <- DT::renderDataTable({
datatable(mtcars %>%
rename("hp <button type='button' id='notWorking' class='btn action-button btn-info btn-xs shiny-bound-input'>
<i class='fa fa-question' role='presentation' aria-label='question icon'></i>
</button>"=hp),
rownames=TRUE,
selection='none',
escape=FALSE)
})
}
shinyApp(ui = ui, server = server)
【问题讨论】: