[英]R Shiny: small table with checkbox columns and a scrollbar
I am trying to make a Shiny app using golem, but I am very new to this.我正在尝试使用 golem 制作一个 Shiny 应用程序,但我对此很陌生。 This time I just want to make a small table with checkboxes and a scroll bar, but I am not succeeding...
这次我只想制作一个带有复选框和滚动条的小表格,但我没有成功......
This is the only thing I manage to make work so far (but even the scrollbar does not seem to show):到目前为止,这是我唯一设法完成的工作(但即使滚动条似乎也没有显示):
mod_saving_side_ui <- function(id){
ns <- NS(id)
tagList(
shinyjs::useShinyjs(),
shinyalert::useShinyalert(),
fluidRow(
DT::DTOutput(ns("my_marker_table"), width = "75%")
)
)
}
mod_saving_side_server <- function(id, r){
moduleServer( id, function(input, output, session){
ns <- session$ns
output$my_marker_table <- DT::renderDT({
marker_df <- data.frame(marker=LETTERS, positive="", negative="")
marker_df$positive[1] <- "y"
marker_df$negative[2:4] <- "y"
marker_matrix <- as.matrix(marker_df)
DT::datatable(marker_matrix, options = list(scrollY = TRUE, sDom = '<"top">rt<"bottom">ip'), rownames = FALSE)
})
})
}
It produces this:它产生这个:
However I would like to accomplish 3 things:但是我想完成三件事:
Previous
1
2
3
Next
buttonsPrevious
1
2
3
Next
按钮positive
and negative
columns have a checkbox per rowpositive
和negative
列有每行一个复选框positive
checkbox preselected for the first row A
, and the negative
checkbox preselected for the 2:4 rows B
, C
, D
A
预选positive
复选框,为 2:4 行B
、 C
、 D
预选negative
复选框How to make checkboxGroupInput
work in here and the scrollbar to show?如何使
checkboxGroupInput
在这里工作并显示滚动条? Thanks!谢谢!
Here's a partial answer, only focused on point 1. I think you should split this post into several ones, it's a bit discouraging when we see a list of things to do instead of a single question.这是部分答案,只关注第 1 点。我认为您应该将这篇文章分成几篇,当我们看到要做的事情列表而不是单个问题时,这有点令人沮丧。
Also, your example is not reproducible (we can't just copy-paste your code to make the app), so I made a basic app instead.此外,您的示例不可重现(我们不能只是复制粘贴您的代码来制作应用程序),所以我制作了一个基本的应用程序。
Basically, I remove the "1", "2", "3", etc. buttons at the bottom of the datatable()
with the argument pageLength
.基本上,我使用参数
pageLength
了datatable()
底部的“1”、“2”、“3”等按钮。 Only doing this produces a very long table, so I use CSS to specify its height (here I put 15em
but it's your choice) and to make it scrollable.只有这样做会产生一个很长的表格,所以我使用 CSS 来指定它的高度(这里我放了
15em
但它是你的选择)并使其可滚动。
library(shiny)
library(DT)
ui <- fluidPage(
tags$head(
tags$style(
HTML(
"#test {
height: 15em !important;
overflow-y: scroll
}"
)
)
),
DTOutput("test")
)
server <- function(input, output, session) {
output$test <- renderDT({
datatable(iris, options = list(
pageLength = nrow(iris)
))
})
}
shinyApp(ui, server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.