【发布时间】:2020-05-14 05:08:18
【问题描述】:
我无法理解使用 Shiny 的 renderDataTable 函数的行为。
我正在尝试扩展 一个 特定 列的宽度。
当我不使用 Shiny 并且只是试图可视化表格的输出时,我编写以下内容并在图中得到预期的输出(Amazon Title 列已扩展):
Category <- c("Tools & Home Improvement", "Tools & Home Improvement")
AmazonTitle <- c("0.15,Klein Tools NCVT-2 Non Contact Voltage Tester- Dual Range Pen Voltage Detector for Standard and Low Voltage with 3 m Drop Protection", " ABCDFGEGEEFE")
ASIN_url <- c("<a href='https://www.amazon.com/dp/B004FXJOQO'>https://www.amazon.com/dp/B004FXJOQO</a>", "<a href='https://www.amazon.com/dp/B004FXJOQO'>https://www.amazon.com/dp/B0043XJOQO</a>")
ASIN <- c("B004FXJOQO", "B0043XJOQO")
All_ASIN_Information <- data.frame(Category, AmazonTitle, ASIN_url, ASIN)
DT::datatable(All_ASIN_Information, escape=FALSE,
options = list(
pageLength = 20, autoWidth = TRUE,
columnDefs = list(list( targets = 2, width = '600px'))
)
)
但是当我在 Shiny 的 DT::renderDataTable 函数中使用这个确切的块时,结果不同并且列宽没有扩展.... 使用以下代码查看 Shiny 的行为:
library(shiny)
library(DT)
ui <- fluidPage(
mainPanel(
DT::dataTableOutput("Table_ASIN")))
server <- function(input, output){
output$Table_ASIN <- DT::renderDataTable(
DT::datatable(All_ASIN_Information, escape=FALSE,
options = list(
pageLength = 20, autoWidth = TRUE,
columnDefs = list(list( targets = 2, width = '600px'))
)))
}
shinyApp(ui, server)
我不知道这种行为是否是由在“ASIN_url”列中创建的超链接引起的,但无论如何我真的需要它们。
对此非常感谢!
【问题讨论】: