-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbd32d9
commit 7eb94ee
Showing
3 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
# InputFile | ||
""" | ||
import textwrap | ||
|
||
import solara | ||
from solara.components.file_drop import FileInfo | ||
from solara.website.utils import apidoc | ||
|
||
|
||
@solara.component | ||
def Page(): | ||
content, set_content = solara.use_state(b"") | ||
filename, set_filename = solara.use_state("") | ||
size, set_size = solara.use_state(0) | ||
|
||
def on_file(file: FileInfo): | ||
set_filename(file["name"]) | ||
set_size(file["size"]) | ||
f = file["file_obj"] | ||
set_content(f.read(100)) | ||
|
||
with solara.Div() as main: | ||
solara.InputFile( | ||
label="Upload file to read first 100 bytes", | ||
on_file=on_file, | ||
lazy=True, # We will only read the first 100 bytes | ||
) | ||
if content: | ||
solara.Info(f"File {filename} has total length: {size:,}\n, first 100 bytes:") | ||
solara.Preformatted("\n".join(textwrap.wrap(repr(content)))) | ||
|
||
return main | ||
|
||
|
||
__doc__ += apidoc(solara.InputFile.f) # type: ignore |