and you ought to see a little pin in the left margin.
that you’ll see plus(+)indications that let you add a new cell to the notebook. Click the lower plus sign to add a brand-new cell
get a dialog to pick and submit a regional file. When you do so, code that achieved the upload ought to pop into the cell. You need to see two lines: one that states something like your_file_name=Range(32) [Item, Object, Things …] and another like your_file_name=FileAttachment (“your_file_name. csv”). csv( )That initially line
service, code in public notebooks is readily available for import and usage in your note pads hosted on ObservableHQ.com. If you want to use that code in an external Quarto file, make certain it’s certified for reuse or that you otherwise have approval. Import a public function To utilize someone else’s function, include the following to your note pad and start using the function with any required arguments as usual: import TheFunctionName from” @user/ notebook-name “You can rename the function, too, using the syntax: import from”@username/ notebook_name”You can then use that code with my_function (mydata)(including any additional function arguments if needed). Keep in mind that you can use the same import from “@user/ notebook-name”code in a Quarto file’s ojs code portion, not just on ObservableHQ.com.Import a cell In a note pad on ObservableHQ.com, clicking the three-dot menu to the left of a named cell ought to show an option to Copy Import if a cell is copyable. As shown in Figure 3, clicking that will provide you the correct import code. Figure 3. Click the three-dot menu to the left of a cell. You will see an alternative to copy the code to import that cell to another note pad.
Recycling code in Observable notebooks A few of the note pads authored by Observable developers do not display licenses for reuse.
Bostock likewise has an example with explanations in his Bar Chart, Horizontal notebook. In this mannerof thinking can help you modularize your own code as well as recycling work from others. And, you can”rewrite code on-the-fly to replace values when importing using Observable’s import-with syntax
,”said Bostock.”This permits you to take content from another note pad, such as a chart, and replace its data with your own, as long as your data has an identical structure(the same column names and types ).”If your data isn’t in the needed format, usage something like array.map to change it into what’s required. See Observable’s Intro to Imports for more details and timelyportfolio’s Quarto example of recycling an information summary table with graphics to produce something like what’s displayed in Figure 4. Figure 4. A table developed by the imported SummaryTable function. You just need 2 lines of code, each in its own notebook cell: import from “@observablehq/ summary-table”SummaryTable(mydata)The two lines must
. Copyright © 2022 IDG Communications, Inc. Source