小编Sah*_*hib的帖子

以 / 分隔的嵌套列表的列

我有一列,其中每个行元素都由“ / ”分隔:

data.frame(column=c("a","a/air","a/aero/breath","b","b/boy","b/bag/band/brand"))
Run Code Online (Sandbox Code Playgroud)

如何在每个“ / ”之后将其转换为嵌套列表。所以目标是获得:

list(a=list("air"=1,aero=list("breath"=1)),b=list("boy"=1,bag=list(band=list("brand"=1)))) 
Run Code Online (Sandbox Code Playgroud)

我需要这个用于 ShinyTree 包来从列中制作一棵树。

我在层次结构中最后一个元素的末尾添加了“=1”,因为它需要显示在 ShinyTree 输出中。然后可以将列表放入下面的代码中以获取tree

library(shiny)
library(shinyTree)

tree <- list(a=list("air"=1,aero=list("breath"=1)),b=list("boy"=1,bag=list(band=list("brand"=1)))) 


typeof(tree)

ui <- fluidPage(
  fluidPage(
    sidebarLayout(
      sidebarPanel(
        actionButton('reset', 'Reset nodes')
      ),
      mainPanel(
        shinyTree("tree", ),
        hr(),
        "Selected nodes:",
        verbatimTextOutput("idSelected")#,
      )
    )
  )
)

server <- function(input, output, session) {
  
  treeSelection <- reactiveVal(list())
  
  output$tree = renderTree({
    tree
  })
  
  observeEvent(input$reset, {
    updateTree(session, "tree", data = tree)
    treeSelection(list())
  })
  
  observeEvent(input$tree, {
    treeSelection(get_selected(input$tree, format = "classid"))
  })
  
  output$idSelected <- renderPrint({
    treeSelection()
  })
  
}

shinyApp(ui, …
Run Code Online (Sandbox Code Playgroud)

r list

6
推荐指数
1
解决办法
66
查看次数

如何在r中对数据帧进行base 64编码

举个例子df <- head(iris)。我如何将其编码为 Base64 字符串。我需要它作为 GitHub API 内容参数。

目前我一直在尝试使用该base64encode()函数,但收到“normalizePath 中的错误”

base64 r github-api

1
推荐指数
1
解决办法
1379
查看次数

标签 统计

r ×2

base64 ×1

github-api ×1

list ×1