[英]Extend width of column with renderDataTable in Shiny
I having trouble understanding the behavior of renderDataTable
function using Shiny.我无法理解使用 Shiny 的
renderDataTable
函数的行为。
I am trying to extend the width of one specific column .我正在尝试扩展一个特定列的宽度。
When I am not using Shiny, and just trying to visualize the output of the table, I write the below and I get the expected output in the plot ( Amazon Title column is extended):当我不使用 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'))
)
)
But when I use this exact block inside a DT::renderDataTable function for Shiny, the result is different and the column width is not extended....但是当我在用于 Shiny 的DT::renderDataTable函数中使用这个确切的块时,结果是不同的并且列宽没有扩展......
See behavior for Shiny with below code:使用以下代码查看 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)
I don't know if this behavior is caused by the hyperlinks created in column 'ASIN_url' but I would really need them anyway.我不知道这种行为是否是由“ASIN_url”列中创建的超链接引起的,但无论如何我真的需要它们。
Any help much appreciated on this !任何帮助都非常感谢!
One option would be to shorten the link like this:一种选择是像这样缩短链接:
ASIN_url <- c("<a href='https://www.amazon.com/dp/B004FXJOQO'>Link</a>", "<a href='https://www.amazon.com/dp/B004FXJOQO'>Link</a>")
Another would be to add a scroll bar by including scrollX = TRUE
in the option list另一种方法是通过在选项列表中包含
scrollX = TRUE
来添加滚动条
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.