R 与2个向量重叠?光辉的榜样

R 与2个向量重叠?光辉的榜样,r,lapply,R,Lapply,我很抱歉,如果这是一个有点多余的帖子,关于lappy与多个参数,但我仍然努力在我的嵌套函数中应用这些概念。如果题目没有触及我问题的关键,我也会道歉,我愿意接受建议 我想从一系列数据框中创建一系列列表,其中每个列表都有一个与数据框名称对应的标题: 期望输出 试验 A B C 测试2 D E F 测试3 G H 我 我首先创建了all_tests,一个包含所有数据帧的列表,其名称对应于数据帧 我想在一系列函数中使用它: rowBlock创建li元素(A、B、C、D、E、F)等 rowP

我很抱歉,如果这是一个有点多余的帖子,关于lappy与多个参数,但我仍然努力在我的嵌套函数中应用这些概念。如果题目没有触及我问题的关键,我也会道歉,我愿意接受建议

我想从一系列数据框中创建一系列列表,其中每个列表都有一个与数据框名称对应的标题:

期望输出 试验

  • A
  • B
  • C
测试2

  • D
  • E
  • F
测试3

  • G
  • H
我首先创建了
all_tests
,一个包含所有数据帧的列表,其名称对应于数据帧

我想在一系列函数中使用它:
  • rowBlock
    创建li元素(A、B、C、D、E、F)等
  • rowPallete
    为每个数据帧创建所有行块的ul元素,以及数据帧的标题
  • rowArea
    根据用户指定的数据帧列表(
    all_tests
    )组合所有行托盘。这是我想在App.R中使用的函数
库(闪亮)
#这是一个重复,实际上我要导入x个数据帧
#我想在每个列表中使用它们的列名
#并为每个列表命名数据帧的名称

test这似乎就是您所追求的(rowBlock保持不变)

#每个数据帧都应该是自己的列表
#并以df的名称命名

rowPallete
Map
是与
lappy
等效的多输入。示例:
Map(粘贴,1:10,11:20)
(是的,这个示例很愚蠢,因为粘贴已经矢量化了,但它说明了映射的工作方式)您是否介意帮我更具体一点,因为这适用于RowPallete函数?我在同一个向量上的同一个函数中使用了两次Lappy,但在尝试为每个列表生成标题时它不起作用(h5)
library(shiny)

# This is a repex where really I'm going to be importing x # of data frames
# I want to use their column names within each list
# And title each list the name of the dataframe
test <- data.frame("A" = NA, "B" = NA, "C" = NA)
test2 <- data.frame("D" = NA, "E" = NA, "F" = NA)
test3 <- data.frame("G" = NA, "H" = NA, "I" = NA)

all_tests <- list(colnames(test), colnames(test2), colnames(test3))
names(all_tests) <- c("test", "test2", "test3")

# each column name should be a li
rowBlock <- function(name) {
  tags$li(
    class = "block", id = name,
    div(name)
  )
}

# each dataframe should be its own list
# and titled with the name of the df
rowPallete <- function(data) {
  div(
    lapply(names(data), h5),
    tags$ul(
      class="all_blocks",
      lapply(data, rowBlock)
    ))
}

# combine the different dataframes into a series of lists
# to be used within app.R
rowArea <- function(bins) {
  column(1, offset = 0, style='padding:0px;',
         lapply(bins, rowPallete)
  )
}
# each dataframe should be its own list
# and titled with the name of the df
rowPallete <- function(data) {
  Map(function(x, y) 
        div(h5(x), tags$ul(class = 'all_blocks', lapply(colnames(y), rowBlock))),
      names(data),
      data)
}

rowArea <- function(bins) {
  column(1, offset = 0, style='padding:0px;',
         rowPallete(bins)
  )
}

ui <- rowArea(all_tests)
server <- function(input, output) {
}

shinyApp(ui = ui, server = server)