- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 509 个
- 通用积分
- 629.6114
- 学术水平
- 16 点
- 热心指数
- 25 点
- 信用等级
- 13 点
- 经验
- 5026 点
- 帖子
- 166
- 精华
- 0
- 在线时间
- 535 小时
- 注册时间
- 2018-8-9
- 最后登录
- 2024-1-30
|
- library(shiny)
- library(kableExtra)
- library(reshape2)
- ui <- fluidPage(
- fluidPage(
- titlePanel("Purchase Order"),
- fluidRow(
- tableOutput("PO")
- )
- )
- )
- server <- function(input, output){
- pohead <- structure(list(
- po_num = c(110, 120, 130),
- Vendor = c("A", "B", "A"),
- Amount = c(1000, 300, 500)
- ),
- row.names = c(NA, -3L),
- class = c("tbl_df", "tbl", "data.frame")
- )
- podetail <- structure(list(
- po_num = c(110, 110, 120, 120, 130),
- Item = c(
- "Toy Cat", "Toy Bear", "Screw",
- "Tools", "Toy Sneak"
- ),
- Amount = c(500, 500, 100, 200, 500)
- ),
- row.names = c(NA, -5L),
- class = c("tbl_df", "tbl", "data.frame")
- )
- podetail <- cbind(podetail)
- PO <- c()
- for (i in 1:nrow(pohead)) {
- num <- pohead[i, ]$po_num
- PO <- rbind(PO, paste(colnames(pohead)))
- PO <- rbind(PO, paste(pohead[i, ]))
- temp <- podetail[podetail$po_num == num, ]
- PO <- rbind(PO, paste(colnames(podetail)))
- for (j in 1:nrow(temp)) {
- PO <- rbind(PO, paste(temp[j, ]))
- }
- }
- output$PO <- renderTable(PO, colnames = F)
- }
- shinyApp(ui = ui, server = server)
复制代码
这种写法有点蛋疼,两个记录的字段还要凑一样长。看来这种类型报表想用R取代Crystal Report有点想多了。
|
|