如何在R中使用selectizeGroupUI和DT::datatable
根据官方文档中的示例,我可以这样做:如何在R中使用selectizeGroupUI和DT::datatable,r,filter,shiny,format,dt,R,Filter,Shiny,Format,Dt,根据官方文档中的示例,我可以这样做: library(shiny) library(shinyWidgets) library(dplyr) data("mpg", package = "ggplot2") ui <- fluidPage( fluidRow( column( width = 10, offset = 1, tags$h3("Filter data w
library(shiny)
library(shinyWidgets)
library(dplyr)
data("mpg", package = "ggplot2")
ui <- fluidPage(
fluidRow(
column(
width = 10, offset = 1,
tags$h3("Filter data with selectize group"),
panel(
selectizeGroupUI(
id = "my-filters",
params = list(
manufacturer = list(inputId = "manufacturer", title = "Manufacturer:"),
model = list(inputId = "model", title = "Model:"),
trans = list(inputId = "trans", title = "Trans:"),
class = list(inputId = "class", title = "Class:")
)
),
status = "primary"
),
DT::dataTableOutput(outputId = "table")
)
)
)
server <- function(input, output, session) {
mpgView2 <- reactive({
mpg
})
res_mod <- callModule(
module = selectizeGroupServer,
id = "my-filters",
data = mpgView2,
vars = c("manufacturer", "model", "trans", "class")
)
output$table <- DT::renderDataTable({
req(res_mod())
res_mod()
})
}
shinyApp(ui, server)
mpgView1 <- reactive({
DT::datatable(
mpg,
filter = "none",
selection = "none",
style = "bootstrap",
extensions = c("Scroller", "FixedColumns"),
options = list(
dom = 't',
scrollY = 500,
scrollX = 400,
scroller = TRUE,
defRender = TRUE,
autoWidth = TRUE,
targets = "no-sort",
bSort = FALSE,
order = c(),
fixedColumns = list(leftColumns = 2),
columnDefs = list(
list(
visible = FALSE,
targets = c(0)
),
list(
width = "50px",
targets = "_all"
)
)
),
editable = list(
target = 'cell',
disable = list(columns = c(0,1,2))
)
) %>%
DT::formatRound(
columns = c(3)
)
})
output$table <- DT::renderDataTable({
mpgView1()
})
库(闪亮)
图书馆(shinyWidgets)
图书馆(dplyr)
数据(“mpg”,package=“ggplot2”)
uiselectizeGroupServer的输出是作为反应的过滤数据,因此您可以在根据需要设置样式的datatable
调用中使用此输出。数据表可编辑的要求带来了一些问题:selectizeGroupServer
需要知道新数据。这是可能的,但是在我的解决方案中,表会完全刷新,并且现有的过滤器会丢失。我认为您可以尝试使用代理
获得更好的行为,但是代理
和selectizeGroupServer
的组合有点棘手
库(闪亮)
图书馆(shinyWidgets)
图书馆(dplyr)
#>
#>武官帕克特:“dplyr”
#>以下对象已从“package:stats”屏蔽:
#>
#>滤波器,滞后
#>以下对象已从“package:base”屏蔽:
#>
#>相交、setdiff、setequal、并集
数据(“mpg”,package=“ggplot2”)
用户界面