Reading trees from a URL
Here, we demonstrate how to read in a tree from a url using a fetch() request from the fetch API. In this case, we read Newick trees from a URL as part of a small app that counts the number of trees in the link and plots the first one with Phylocanvas.
The fetch() request is nested in the function treesFromURL(), which also handles plotting data to the screen. Key features are that the fetch request is asynchronous, so we annotate it with await and annotate the wrapper function with async. You can learn more about asynchronous function in JavaScript here
You can copy a url linking 5 trees that we use for testing here:
https://raw.githubusercontent.com/clockor2/phylojs/main/test/data/egTree.nwk
See the Pen fetch-url-tree by Leo Featherstone (@LeoFeatherstone) on CodePen.