Observable Framework View source

Selecting files

This example demonstrates how to select a file from a drop-down menu using Inputs.select. FileAttachment requires a static string literal argument, so the value of the select is a FileAttachment rather than a string.

const file = view(Inputs.select([
  FileAttachment("data/buy-a-boat-cat.jpg"),
  FileAttachment("data/is-this-a-pigeon.jpg"),
  FileAttachment("data/picard-annoyed.jpg"),
  FileAttachment("data/picard-facepalm.jpg")
], {
  format: (d) => d.name
}));
file

To load the file, call the desired contents method. For example, for an image:

file.image({width: 640}) // load the image