Skip to content

jsTreeR disables reactive callbacks from bslib nav containers #33

Open
@datatenk

Description

@datatenk

This problem may be related to issue: #32 (comment)

After switching from shinyTree to jsTreeR, the callbacks from bslib::navset_pill_list appears to be broken when rendered through renderUI. The desirable behavior is that whenever the user activates a certain nav_panel in the navset_pill_list container, the value the nav_panel should be accessible through the input$id_of_navset_pill_list_container. However, when jsTreeR is used with renderUI, the input$id_of_navset_pill_list_container is never updated when the user activates certain panels, and remains at the initialized value of NULL at all times.

2 Reprex's are made with shinyTree and jsTreeR

Firstly, the reprex with shinyTree showing desirable reactive behaviour:

library(shiny)
library(bslib)
library(shinyWidgets)
library(shinyTree)
library(jsTreeR)

# using shinyTree
nodes_shinyTree<-list(foo=list(bar=list()))

shinyTree_ui<-card(
  shinyTree('shinyTree_tree_ui'),
  verbatimTextOutput(outputId='selected_navset_ui'),
  bslib::navset_pill_list(
    id='navset_ui',
    nav_panel(title="A",value="A"),
    nav_panel(title="B",value="B"))
)

ui_shinyTree<-page_navbar(
  title='shinyTree',
  
  nav_panel(
    title='shinyTree',
    card(
      shinyTree('shinyTree_tree'),
      verbatimTextOutput(outputId='selected_navset'),
      bslib::navset_pill_list(
        id='navset',
        nav_panel(title="A",value="A"),
        nav_panel(title="B",value="B"))
    )
  ),

  nav_panel(
    title='shinyTree uiOutput',
    uiOutput('shinyTree_ui')
  )
  
)

server_shinyTree<-function(input,output,session){
  output$shinyTree_tree<-renderTree(nodes_shinyTree)
  output$selected_navset<-renderText(input$navset)

  output$shinyTree_ui<-renderUI(shinyTree_ui)
  output$shinyTree_tree_ui<-renderTree(nodes_shinyTree)
  output$selected_navset_ui<-renderText({
    if(is.null(input$navset_ui)){
      'select from navset'  
    } else {
      input$navset_ui  
    }
  })
  
}

shinyApp(ui_shinyTree,server_shinyTree)

Now the reprex with jsTreeR, where the input$navset_ui fails to update on change:

library(shiny)
library(bslib)
library(shinyWidgets)
library(shinyTree)
library(jsTreeR)

# using jsTreeR
nodes_jsTreeR<-list(list(text='foo',children=list(list(text='bar'))))

jsTreeR_ui<-card(
    jstreeOutput('jstree_tree_ui'),
    verbatimTextOutput(outputId='selected_navset_ui'),
    bslib::navset_pill_list(
      id='navset_ui',
      nav_panel(title="A",value="A"),
      nav_panel(title="B",value="B"))
)


ui_jsTreeR<-page_navbar(
  title='jsTreeR',
  
  nav_panel(
    title='jsTreeR',
    card(
      jstreeOutput('jstree_tree'),
      verbatimTextOutput(outputId='selected_navset'),
      bslib::navset_pill_list(
        id='navset',
        nav_panel(title="A",value="A"),
        nav_panel(title="B",value="B"))
    )
  ),

  nav_panel(
    title='jsTreeR uiOutput',
    uiOutput('jsTreeR_ui')
  )
)

server_jsTreeR<-function(input,output,session){
  output$jstree_tree<-renderJstree(jstree(nodes_jsTreeR))
  output$selected_navset<-renderText(input$navset)
  
  
  output$jsTreeR_ui<-renderUI(jsTreeR_ui)
  output$jstree_tree_ui<-renderJstree(jstree(nodes_jsTreeR))
  output$selected_navset_ui<-renderText({
    if(is.null(input$navset_ui)){
      'select from navset'  # This is always displayed
    } else {
      input$navset_ui  # This is never displayed since input$navset_ui never updates
    }
  })
  
}

shinyApp(ui_jsTreeR,server_jsTreeR)

The reprex's differ only by which wrapper is used to interface with jsTree (shinyTree vs jsTreeR).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions