我正在使用 shinyTree 包在 R Shiny 中创建树视图,能够做到这一点。已用于服务器部分的代码具有列表创建功能。现在,额外的要求是将数据框转换为列表并导入相同的内容以使用renderTree实现树结构。
这是我编写的代码:
#ui part
library(shiny)
library(shinyTree) # Using shinyTree Package
# UI for application that demonstrates a Tree View
shinyUI(
pageWithSidebar(
# Application title
headerPanel("Tree View in Shiny"),
sidebarPanel(
helpText(HTML("A simple Shiny Tree example.
<hr>Created using shinyTree Package."))
),
mainPanel(
# Show a simple table.
shinyTree("tree")
)
))
#--------------------------------------------------------------------
#server part
library(shiny)
library(shinyTree)
# server logic required to generate a tree structure
shinyServer(function(input, output, session) {
output$tree <- renderTree({
**list(
Folder1 = list(File1.1 = structure("",sticon="file"), File1.2 = structure("",sticon="file")),
Folder2 = list(
Subfolder2.1 = list(File2.1.1 = structure("",sticon="file"), File2.1.2 = structure("",sticon="file")
, File2.1.3=structure("",sticon="file")),
Subfolder2.2 = list(File2.2.1 = structure("",sticon="file"), File2.2.2 = structure("",sticon="file")),
File2.3 = structure("",sticon="file")
)**
)
})
})
代码的星号部分需要替换为列表(已使用数据框转换)。我怎样才能做到这一点。