flexboard shiny table 水平和垂直滚动条不工作
flexboard shiny table horizontal and vertical scrollers not working
我刚刚将一个 csv 数据导入到 R 的 flexdashboard 中并闪亮并想在其中一个图表网格中显示 table,下面是我为此使用的代码。我希望显示垂直和水平滚动条,但它们似乎不起作用,知道我错在哪里吗?
数据方面,可以暂时使用MTCARS。
Row
-------------------------------------
### DATA
```{r}
data_set <- reactive({
inFile <- input$file1
if (is.null(inFile))
return(NULL) else return ( read.csv(inFile$datapath, header = input$header, stringsAsFactors =FALSE) )
})
output$tbl <-DT::renderDataTable({
if (is.null(data_set()))
return(NULL) else return (
DT::datatable(data_set(),
#style='bootstrap', class='table-condensed',
#editable=FALSE,
rownames=FALSE,
options = list(
scrollX = '400px', scrollY='360px',
searchHighlight=TRUE, pageLength = 4
))
)
})
div(style = "overflow-x: scroll; overflow-y: scroll;", DTOutput("tbl"))
```
添加数据:
structure(list(Gender = c("Male", "Male", "Male", "Male", "Male",
"Male", "Male", "Male", "Male", "Male"), Height = c(73.847017017515,
68.7819040458903, 74.1101053917849, 71.7309784033377, 69.8817958611153,
67.2530156878065, 68.7850812516616, 68.3485155115879, 67.018949662883,
63.4564939783664), Weight = c(241.893563180437, 162.3104725213,
212.7408555565, 220.042470303077, 206.349800623871, 152.212155757083,
183.927888604031, 167.971110489509, 175.92944039571, 156.399676387112
), BMI = c(0.0443566151469252, 0.0343082174614673, 0.0387343292394288,
0.0427654457094595, 0.0422547891767963, 0.033653156898047, 0.0388739862001733,
0.0359564180086832, 0.039169072415755, 0.0388404008602306), probability = c(5.77831234737499e-06,
0.605952546493327, 2.62595199514618e-05, 0.000362873417265588,
0.00461190097404834, 0.911068673692331, 0.0496119303175197, 0.352335117615303,
0.139124546478089, 0.343426515632885)), row.names = c(NA, 10L
), class = "data.frame")
虽然我无法在您的特定示例中对此进行测试,因为它不是最低限度可重现的,但我可以共享这段代码,该代码在我当前的生产 flexdashboards 之一中工作,它是在 renderDT
中创建的数据表,而不是renderDataTable
避免命名冲突。在这个例子中,data_set()
是被动的。
滚动由 scrollX
和 scrollY
选项控制:
renderDT({
datatable(data_set(), style='bootstrap',
class='table-condensed', editable=FALSE, rownames=FALSE,
options = list(
scrollX = '400px', scrollY='360px',
searchHighlight=TRUE, order=list(0, 'asc'),
))
})
这是我的代码示例,其中 renderDataTable
和 scrollY
有效。我正在使用从本节更新的反应式 df。
renderDataTable({
# Table only updates after the df as it is wrapped in an
# eventReactive
if (!(is.null(query_data$$df))) {
query_data$df %>%
select(JobID, PartID, `Short Desc`)
}
},
options = list(
scrollY = "43vh",
dom = "ft",
fixedColumns = TRUE,
autoWidth = TRUE,
ordering = TRUE,
pageLength = -1)
)
关键部分是获得正确的选项,dom
选项允许您设置相当多的参数 dom = "ft"
启用过滤器并将其放在 table 之上。
pageLength = -1
显示df中的所有数据。
您应该查看 https://datatables.net/ 了解更多信息
我刚刚将一个 csv 数据导入到 R 的 flexdashboard 中并闪亮并想在其中一个图表网格中显示 table,下面是我为此使用的代码。我希望显示垂直和水平滚动条,但它们似乎不起作用,知道我错在哪里吗?
数据方面,可以暂时使用MTCARS。
Row
-------------------------------------
### DATA
```{r}
data_set <- reactive({
inFile <- input$file1
if (is.null(inFile))
return(NULL) else return ( read.csv(inFile$datapath, header = input$header, stringsAsFactors =FALSE) )
})
output$tbl <-DT::renderDataTable({
if (is.null(data_set()))
return(NULL) else return (
DT::datatable(data_set(),
#style='bootstrap', class='table-condensed',
#editable=FALSE,
rownames=FALSE,
options = list(
scrollX = '400px', scrollY='360px',
searchHighlight=TRUE, pageLength = 4
))
)
})
div(style = "overflow-x: scroll; overflow-y: scroll;", DTOutput("tbl"))
```
添加数据:
structure(list(Gender = c("Male", "Male", "Male", "Male", "Male",
"Male", "Male", "Male", "Male", "Male"), Height = c(73.847017017515,
68.7819040458903, 74.1101053917849, 71.7309784033377, 69.8817958611153,
67.2530156878065, 68.7850812516616, 68.3485155115879, 67.018949662883,
63.4564939783664), Weight = c(241.893563180437, 162.3104725213,
212.7408555565, 220.042470303077, 206.349800623871, 152.212155757083,
183.927888604031, 167.971110489509, 175.92944039571, 156.399676387112
), BMI = c(0.0443566151469252, 0.0343082174614673, 0.0387343292394288,
0.0427654457094595, 0.0422547891767963, 0.033653156898047, 0.0388739862001733,
0.0359564180086832, 0.039169072415755, 0.0388404008602306), probability = c(5.77831234737499e-06,
0.605952546493327, 2.62595199514618e-05, 0.000362873417265588,
0.00461190097404834, 0.911068673692331, 0.0496119303175197, 0.352335117615303,
0.139124546478089, 0.343426515632885)), row.names = c(NA, 10L
), class = "data.frame")
虽然我无法在您的特定示例中对此进行测试,因为它不是最低限度可重现的,但我可以共享这段代码,该代码在我当前的生产 flexdashboards 之一中工作,它是在 renderDT
中创建的数据表,而不是renderDataTable
避免命名冲突。在这个例子中,data_set()
是被动的。
滚动由 scrollX
和 scrollY
选项控制:
renderDT({
datatable(data_set(), style='bootstrap',
class='table-condensed', editable=FALSE, rownames=FALSE,
options = list(
scrollX = '400px', scrollY='360px',
searchHighlight=TRUE, order=list(0, 'asc'),
))
})
这是我的代码示例,其中 renderDataTable
和 scrollY
有效。我正在使用从本节更新的反应式 df。
renderDataTable({
# Table only updates after the df as it is wrapped in an
# eventReactive
if (!(is.null(query_data$$df))) {
query_data$df %>%
select(JobID, PartID, `Short Desc`)
}
},
options = list(
scrollY = "43vh",
dom = "ft",
fixedColumns = TRUE,
autoWidth = TRUE,
ordering = TRUE,
pageLength = -1)
)
关键部分是获得正确的选项,dom
选项允许您设置相当多的参数 dom = "ft"
启用过滤器并将其放在 table 之上。
pageLength = -1
显示df中的所有数据。
您应该查看 https://datatables.net/ 了解更多信息