jsTreeR 错误以及如何将其用作 shiny 中的输入

jsTreeR bug and how to use it as an input in shiny

提问人:akshay bholee 提问时间:10/18/2023 最后编辑:ismirsehregalakshay bholee 更新时间:10/19/2023 访问量:38

问:

我正在尝试创建一个树层次结构输入参数。我知道我们应该能够使用 jsTreeR 包来做到这一点。我首先尝试像这样构建树层次结构:

library(jsTreeR)

nodes <- list(
  list(
    text = "RootA",
    type = "root",
    children = list(
      list(
        text = "ChildA1",
        type = "child",
        children= list( list(text = "ChildA12",
                        type = "child"))
      ),
      list(
        text = "ChildA2",
        type = "child"
      )
    )
  ),
  list(
    text = "RootB",
    type = "root",
    children = list(
      list(
        text = "ChildB1",
        type = "child"
      ),
      list(
        text = "ChildB2",
        type = "child"
      )
    )
  )
)

types <- list(
  root = list(
    icon = FALSE
  ),
  child = list(
    icon = FALSE
  )
)

jstree(
  nodes,
  types = types,
  checkboxes = TRUE
)

但是,当我扩展层次结构时,有时会出现一个错误,有时第一个子项与下面的第二个子项重叠,如下所示:

enter image description here

如何解决这个问题?

其次,我想将这棵树用作输入,但在闪亮应用程序的下拉列表中。如何做到这一点?

r 闪亮 的树 jstree jstreer

评论

1赞 ismirsehregal 10/18/2023
在这里提出了一个问题。
1赞 Stéphane Laurent 10/18/2023
请参阅 中的闪亮值部分,以使用树作为输入。?jstree-shiny
0赞 akshay bholee 10/19/2023
谢谢你@StéphaneLaurent我明白了。它似乎同时是输出和输入。

答:

0赞 akshay bholee 10/19/2023 #1

这是我试图做的一个工作示例。闪亮的错误未见:

library(shiny)
library(jsTreeR)

ui <- fluidPage(
  dropdownButton(
    inputId = "mydropdown",
    label = "HS",
    icon = icon("sliders"),
    status = "primary",
    circle = FALSE,
    jstreeOutput("mytree")

  )
  
)

server <- function(input, output, session) {
  output$mytree <- renderJstree({
    
    nodes <- list(
      list(
        text = "RootA",
        type = "root",
        children = list(
          list(
            text = "ChildA1",
            type = "child",
            children= list( list(text = "ChildA12",
                                 type = "child"))
          ),
          list(
            text = "ChildA2",
            type = "child"
          )
        )
      ),
      list(
        text = "RootB",
        type = "root",
        children = list(
          list(
            text = "ChildB1",
            type = "child"
          ),
          list(
            text = "ChildB2",
            type = "child"
          )
        )
      )
    )
    
    types <- list(
      root = list(
        icon = FALSE
      ),
      child = list(
        icon = FALSE
      )
    )
    # create the tree widget
    
    jstree(
      nodes,
      types = types,
      checkboxes = TRUE
    )
  })

}

shinyApp(ui, server)