【发布时间】:2023-03-27 01:20:01
【问题描述】:
我的 Shiny 应用程序有问题。 在我的应用程序中,我有很多 DT,Box,有时是 DT in Box,所以我决定创建函数来让我的代码更干净。
- 我创建 DT 的函数获取我想要可视化的数据
- 我创建盒子的函数获取盒子的标题,如果是的话应该是 折叠,和 UI - 应该包含什么框(例如几个 像 这样的元素
fluidRow( column(6, uiOutput("aaa")), column(6, uiOutput("bbb")) )
- 我还创建了基于前面描述的函数在 Box 中创建 DT 的函数。
据我了解,问题出在数据传输方式上,但我无法解决。
我准备了我想要实现但不起作用的功能示例。
library(shiny)
library(shinydashboard)
library(DT)
Create_DT <- function(dataSource){
datatable(
dataSource,
rownames = FALSE,
selection = 'none',
class = 'cell-border stripe',
extensions = 'Buttons',
options = list(
buttons = list('copy', 'print', list(extend = 'collection',buttons = c('csv', 'excel', 'pdf'),text = 'Download')),
dom = 'Bfrtip',
info = FALSE,
lengthChange = FALSE,
paging = FALSE,
searching = FALSE,
scrollX = TRUE,
columnDefs = list(list(className = 'dt-center', targets = "_all"))
)
) %>% formatStyle(colnames(dataSource),"white-space"="nowrap")
}
Create_Box <- function(description, collapsed, ui){
box(
width = 12,
title = strong(description),
color = "primary",
collapsible = TRUE,
collapsed = collapsed,
ui
)
}
Create_DTinBox <- function(description, collapsed, ui){
Create_Box(description, collapsed, ui)
}
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
uiOutput("result")
)
)
server <- function(input, output){
reactiveValues(iris = iris)
output$result <- renderUI({
Create_DTinBox(
description = "test",
collapsed = TRUE,
ui = column(6, offset = 3, Create_DT(reactiveValues$iris))
)
})
}
shinyApp(ui, server)
知道这个应用程序在保持示例中的函数结构的同时应该如何正常工作吗?
【问题讨论】: