问题描述
我在flexdashboard中使用shinytree有问题。在常规的闪亮应用程序中效果很好:
library(shiny)
library(shinytree)
server <- function(input,output) {
output$tree <- renderTree({
opciones = list('All'= list(
'Human' = structure(list('OP1'='OP1','OP2'='OP2'),stopened=TRUE),'Mouse' = structure(list('OP3'='OP3'),stopened=TRUE)))
attr(opciones[[1]],"stopened")=TRUE
opciones
})
}
ui <- fluidPage(
shinytree("tree",checkBox = "TRUE")
)
shinyApp(ui = ui,server = server)
但是,当我在Flexdashboard中使用它时,它将返回一个空选项卡(请参见此文件:https://mega.nz/file/DCozwIiJ#ttcBe581FPfhINVoczfBvaXhgRlXwVSu-wd2JhXTEEY)
您是否知道为什么会发生这种情况以及如何在flexdashboard中创建js树复选框?
解决方法
jsTreeR
软件包可以做的比shinyTree
软件包还要多。它可以与flexdashboard
一起正常工作:
---
title: "Untitled"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
runtime: shiny
---
```{r setup,include=FALSE}
library(flexdashboard)
library(shiny)
library(jsTreeR)
```
```{r}
nodes <- list(
list(
text = "RootA",data = list(value = 999),icon = "far fa-moon red",children = list(
list(
text = "ChildA1",icon = "fa fa-leaf green"
),list(
text = "ChildA2",icon = "fa fa-leaf green"
)
)
),list(
text = "RootB",children = list(
list(
text = "ChildB1",list(
text = "ChildB2",icon = "fa fa-leaf green"
)
)
)
)
output[["jstree"]] <- renderJstree({
jstree(nodes,dragAndDrop = TRUE,checkboxes = TRUE,theme = "proton")
})
output[["treeSelected"]] <- renderPrint({
input[["jstree_selected"]]
})
```
Column {data-width=400}
-----------------------------------------------------------------------
### Checkbox tree
```{r}
jstreeOutput("jstree")
```
Column {data-width=400}
-----------------------------------------------------------------------
### Selected nodes
```{r}
verbatimTextOutput("treeSelected")
```
### Chart C
```{r}
```