visNetwork R Package

repository·master·Indexed 20 days ago

https://github.com/datastorm-open/visnetwork

An R package providing an interface to the vis.js library for creating interactive network visualizations within R and Shiny environments. Includes utilities for exporting canvas content via canvas-toBlob.js and FileSaver.js, as well as integration with Tipue Search for documentation indexing.

Tokens
2.7K
Snippets
13
Records
17
Agent score
69%

What's inside visNetwork

  1. Polyfill canvas.toBlob() and canvas.toBlobHD() with canvas-toBlob.js

    master

    The canvas-toBlob.js utility provides polyfills for the standard HTML5 canvas.toBlob() and canvas.toBlobHD() methods. This is useful for ensuring network visualizations can export canvas content in browsers that do not natively support these methods.

    Requirement: canvas-toBlob.js requires Blob support to function. If you are targeting browsers that lack Blob support, you must also include a cross-browser Blob implementation like Blob.js.

  2. Install visNetwork

    master

    You can install the stable version of visNetwork from CRAN using install.packages(). If you need the development version, use devtools::install_github().

    # Install stable version from CRAN
    install.packages("visNetwork")
    
    # Install development version
    devtools::install_github("datastorm-open/visNetwork")
  3. Create a minimal network visualization

    master

    To create a basic network, define a nodes data frame with an id column and an edges data frame with from and to columns. Pass both to the visNetwork() function.

    require(visNetwork)
    
    nodes <- data.frame(id = 1:3)
    edges <- data.frame(from = c(1,2), to = c(1,3))
    visNetwork(nodes, edges)
  4. API Reference: saveAs()

    master

    The primary method provided by FileSaver.js is saveAs().

    Signature: FileSaver saveAs(Blob data, DOMString filename, optional Boolean disableAutoBOM)

    Parameters:

    • data: The Blob object containing the data to be saved.
    • filename: The name of the file to be saved.
    • disableAutoBOM (optional): A boolean. If set to true, FileSaver.js will not automatically provide Unicode text encoding hints (Byte Order Mark).
    FileSaver saveAs(Blob data, DOMString filename, optional Boolean disableAutoBOM)
  5. Configure Tipue Search pages and stop words

    master

    Tipue Search uses specific global variables to define the scope of the search index and which words should be ignored during indexing.

    • tipuesearch_pages: An array of strings containing the relative paths to the HTML pages that should be included in the search index.
    • tipuesearch_stop_words: An array of strings representing words that the search engine should ignore (e.g., common articles and prepositions).
    var tipuesearch_pages = [
      "../network/layout.html",
      "../network/configure.html"
    ];
    
    var tipuesearch_stop_words = ["a", "about", "above"];
  6. Customize Tipue Search UI strings

    master

    You can localize or customize the text displayed in the Tipue Search interface by overriding the tipuesearch_string_N variables (where N is 1 through 13).

    Available string keys:

    • tipuesearch_string_1: 'No title'
    • tipuesearch_string_2: 'Showing results for'
    • tipuesearch_string_3: 'Search instead for'
    • tipuesearch_string_4: '1 result'
    • tipuesearch_string_5: 'results'
    • tipuesearch_string_6: 'Prev'
    • tipuesearch_string_7: 'Next'
    • tipuesearch_string_8: 'Nothing found'
    • tipuesearch_string_9: 'Common words are largely ignored'
    • tipuesearch_string_10: 'Search too short'
    • tipuesearch_string_11: 'Should be one character or more'
    • tipuesearch_string_12: 'Should be'
    • tipuesearch_string_13: 'characters or more'
    var tipuesearch_string_1 = 'Custom Title';
    var tipuesearch_string_8 = 'No matches found';