🏠 back to Observable

Detecting the "No file chosen" state in a file input

I’m working on a notebook where I want to start with my own image as an example, but allow the reader to replace it with a local image file.

This means that I need to be able to detect if my file input is in the “No file chosen” state, so that I can use the default image in that case. But I can’t figure out how to detect that, with either the file input from


or the more basic method from

When I try to inspect the value of the file input when it is in the “No file chosen” state, I get a blank cell. What am I missing? Thanks!

The input in the following notebook was convenient for me when doing similar things:

Ah, great, thank you! I did not come across that example when searching.

If you want to provide a dropdown of example choices in addition to choosing a local file, you could also borrow from this notebook:

1 Like