What is the best way to display hover-over text pop ups on menu list items in jsTreeR?

As a dedicated user of the jsTreeR package within Shiny, I have been exploring the functionality it offers. By executing the code below, users are presented with a draggable menu at the top, allowing them to drag items down to the designated list labeled ">> Drag here <<" to create a custom sequentially labeled list. Is there a way to incorporate hover-over pop-ups with explanatory text when hovering over these menu items, as shown in the illustration below? How can this be achieved?

Once an element is dragged down, the need for the same hover-over pop-up diminishes, only applicable to elements in the "Menu" section at the top.

https://i.sstatic.net/LJXdH.png

Code:

library(jsTreeR)
   library(shiny)

   nodes <- list(
     list(
       text = "Menu",
       state = list(opened = TRUE),
       children = list(
         list(text = "Dog", type = "moveable", state = list(disabled = TRUE)),
         list(text = "Cat", type = "moveable", state = list(disabled = TRUE))
       )
     ),
     list(text = ">> Drag here <<", type = "target", state = list(opened = TRUE))
   )

   dnd <- list(
     always_copy = TRUE,
     inside_pos = "last",
     is_draggable = JS(
       "function(node) {",
       "  return node[0].type === 'moveable';",
       "}"
     )
   )

   mytree <- jstree(
     nodes, dragAndDrop = TRUE, dnd = dnd,
     types = list(moveable = list(), target = list())
   )

   script <- '
   $(document).ready(function(){
     var LETTERS = ["A", "B", "C"];
     var Visited = {};
     $("#mytree").on("copy_node.jstree", function(e, data){
       var oldid = data.original.id;
       var visited = Object.keys(Visited);
       if(visited.indexOf(oldid) === -1){
         Visited[oldid] = 0;
       }else{
         Visited[oldid]++;
       }
       var letter = LETTERS[Visited[oldid]];
       var node = data.node;
       var id = node.id;
       var index = $("#"+id).index() + 1;
       var text = index + ". " + node.text + " " + letter;
       Shiny.setInputValue("choice", text);
       var instance = data.new_instance;
       instance.rename_node(node, text);
     });
   });
   '

   ui <- fluidPage(
     tags$head(tags$script(HTML(script))),
     fluidRow(jstreeOutput("mytree"))
   )

   server <- function(input, output, session){
     output[["mytree"]] <- renderJstree(mytree)
   }

   shinyApp(ui, server)
 

Answer №1

I. Easiest, most straightforward method:

  1. Include a title attribute to the node.
children = list(
      list(text = "Dog",type = "moveable",state = list(disabled = TRUE), a_attr = list(title = "A domesticated carnivorous mammal etc...")),
      list(text = "Cat",type = "moveable",state = list(disabled = TRUE), a_attr = list(title = "A small domesticated carnivorous mammal etc..."))
    )

II. Personalized, although imperfect approach:

  1. Add an id to the children you are interested in:
children = list(
      list(text = "Dog",type = "moveable",state = list(disabled = TRUE), a_attr = list(id = "child_dog")),
      list(text = "Cat",type = "moveable",state = list(disabled = TRUE), a_attr = list(id = "child_cat"))
    )
  1. Utilize the library(shinyBS) to set your tooltips:
ui <- fluidPage(
  tags$head(tags$script(HTML(script))),
  bsTooltip("child_dog", "A domesticated carnivorous mammal etc...",
            "right", options = list(container = "body"), trigger = "hover"),
  bsTooltip("child_cat", "A small domesticated carnivorous mammal etc...",
            "right", options = list(container = "body"), trigger = "hover"),
 
  fluidRow(jstreeOutput("mytree"))
)
  1. However, when collapsing and then expanding the parent folder, the tooltip may become unresponsive. The cause of this issue is unknown at the moment, possibly related to changes in javascript's selectors or ids for nodes.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieving information from a JSON object in Angular using a specific key

After receiving JSON data from the server, I currently have a variable public checkId: any = 54 How can I extract the data corresponding to ID = 54 from the provided JSON below? I am specifically looking to extract the values associated with KEY 54 " ...

An issue has occurred with NPM CI where the bindings are not available from watchpack-chokidar2:fsevents

After executing npm ci on GitHub Actions, I encountered the following error: Run npm ci npm ERR! bindings not accessible from watchpack-chokidar2:fsevents npm ERR! A complete log of this run can be found in: npm ERR! /home/runner/.npm/_logs/2021-09-17 ...

In Angular's production build on Webkit/Safari, the left-hand side of the operator '=' must be a reference

Recently, I completed a project using Angular. After successfully building it for production without any errors, everything seemed to work perfectly on Chrome. However, when attempting to run the app on Webkit/Safari, an error was displayed in the cons ...

Utilizing lapply to apply various functions depending on a condition

I am seeking guidance on utilizing multiple functions in lapply while incorporating a condition. Below is the data frame: Data <- data.frame(c(1:6),c(7:12), c(1,0,1,0,1,1), 0) colnames(Data) <- c("a","b","c","d") My objective is to apply a specific ...

Create additional object property and include in current object's properties dynamically

I have a JSON object that looks like this: "highChart":{ "xAxis":{ "categories":[ "SYN 13 ", "Settlement", "Service Interaction", "FNOL", ...

Error: Unexpected token : encountered in jQuery ajax call

When creating a web page that requests remote data (json), using jQuery.ajax works well within the same domain. However, if the request is made from a different domain (e.g. localhost), browsers block it and display: No 'Access-Control-Allow-Or ...

Display a loading indicator while Axios sends the Ajax request

I'm currently working on a Vue app and I am utilizing Axios for API calls. Before each call, I display a loading icon that hides once the call is completed. I'm curious if there is a way to implement this functionality globally so that I don&apo ...

Fixed bar on top, revealed only when the scroll attempts to conceal it

I have placed a menu on the top section of my website, but not at the very top. I would like it to stick to the top of the page when the user scrolls down and disappears from view. However, if the title is still visible, I want the menu to remain below it ...

What is the best way to retrieve widget options when inside an event?

Creating a custom jQuery widget: jQuery.widget("ui.test",{ _init: function(){ $(this.element).click(this.showPoint); }, showPoint: function(E){ E.stopPropagation(); alert(this.options.dir); } } Initializing the cu ...

``So, you're looking to retrieve a collection of objects that have a OneToMany

Is there a way to retrieve a list of objects with a OneToMany relation using TypeORM's queryBuilder? This is the desired output: { "id": 1, "firstName": "Bob", "lastName": "Sparrow", "orders": [ { "id": 1, "name": "Very Big Or ...

Preserve the table's state even after submitting the form

My php page initially displays a table by default, which is: echo "<table class='tftable' border='1' id='table_L'>"; There is also another table: echo "<table class='tftable' border='1' id=&apos ...

Struggling with uploading files in AngularJS?

Below is the code snippet from my controller file where I aim to retrieve the values of various input elements (name, price, date, image) and store them in an array of objects... $scope.addBook = function(name, price, date, image) { name = $scope ...

Update the delivery status of an Uber Eats order using the Uber Eats API

Hey there, I hope everyone is doing well. I need to update the delivery status of orders on Uber Eats through my app. I am in partnership with Uber Eats and using the Update Delivery Status API for this purpose. The API requires the scope eats.store.order ...

Searching for and replacing text that spans across multiple nodes in HTML can be accomplished using C# programming language

Here is the HTML code to consider. The term 'response' was modified to 'reason', by removing 'sp' (<del> tag) and adding 'as' (<ins> tag), while also removing 'se' (<del> tag). <div &g ...

Error: Attempted to update user profile with an invalid function in Firebase

After creating an Avatar Chooser, I am encountering an error when selecting an image. Instead of displaying the selected image in the avatar, the error message is being displayed. How can I resolve this and ensure that the image appears in the Avatar Icon ...

An object-c alternative to encodeURIComponent

Having difficulty finding information on this through a search engine. Is there a similar method in Objective-C for encoding URI components? http://www.w3schools.com/jsref/jsref_encodeuricomponent.asp This is a common task, but I am unable to locate any ...

Struggling to convert my GRAPHQL response into a JSON object that can be iterated through

Here's a little context: I'm currently working with Shopify's GraphQL API and making calls to retrieve data. The data retrieval process is successful, however, I'm facing a challenge in manipulating the data using regular JSON syntax. M ...

"Unveiling the power of canvas layers in creating dynamic

Curious about the process of achieving this task. Draw, pause for 1 second. Draw frame 2, pause for 1 second. Draw frame 3, pause for 1 second. Clear animation canvas. I believe the solution involves working on an overlapping canvas to avoid being erased ...

Display the personalized list of user items on the MERN dashboard

I'm currently developing a React booking platform that interacts with my backend through a Rest API using axios and redux. My challenge now is to display personalized reservations and rooms for each user on the website. However, I'm facing an iss ...

Combining databases in R just like merging time series

Two sets of data are provided: > x Date Values_X Names_X [1,] "01.01.2012" "1" "A" [2,] "02.01.2012" "2" "B" [3,] "01.02.2012" "3" "C" and > y Date Values_Y Colors_Y [1,] "01.01.2012" "1" "red ...