Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Upload Widget #136

Open
TransGirlCodes opened this issue Dec 8, 2016 · 9 comments
Open

File Upload Widget #136

TransGirlCodes opened this issue Dec 8, 2016 · 9 comments
Assignees

Comments

@TransGirlCodes
Copy link

TransGirlCodes commented Dec 8, 2016

Hi, sometimes I want a user to be able to upload data to a jupyter session in order to use code on the notebook on their own data files, I've found:

https://pypi.python.org/pypi/fileupload/

But it's python, I wondered if a similar widget could be added to Interact.jl for julia?

@TransGirlCodes
Copy link
Author

TransGirlCodes commented Dec 8, 2016

I am happy to work on this issue if someone could help me out and let me know a bit more about what would be involved and in general how this package works. For example, I know ipywidgets is needed, presumably as I can't see any drawing or js code for the widgets defined in src/widgets.jl, ipywidgets contains js and other code that draws them.

@JobJob
Copy link
Member

JobJob commented Dec 9, 2016

I made a quick start on this:

Pkg.checkout("Interact","jbj/file-upload")
Pkg.checkout("IJulia") #IJulia master is required
using Interact
fuw = fileuploader("up up")
display(fuw)

Requires you to have followed the install instructions here: https://github.com/peteut/ipython-file-upload
You'll have to change this method to do something good, I guess probably just call a callback, which you can set up on creation.

If use use IJulia.set_verbose() or look in the network tab in the browser console, you can see what info the widget syncs with the kernel.

P.S. Better to base your changes off that branch rather than master because it is built on top of a fair few new changes that are likely to get merged.

@TransGirlCodes
Copy link
Author

TransGirlCodes commented Dec 9, 2016

Wow that looks pretty great, thank you! I will try and read this and understand, but I think a guide on how to create new widgets for Interact.jl would be ideal, if you give me a heads up on the things you needed to define and why I could start to make such a guide as I struggle through this. I guess lots of the behaviour and so on is handled by julia code, but the drawing the widget in the front end is handled by the ipython-file-upload that is required. That's just my guess though: My reasoning being ipywidgets have a python model and then a js model, and if ipython-file-upload has the js model already, then only the julia model needs to be implemented.

@JobJob
Copy link
Member

JobJob commented Dec 9, 2016

I am just in the middle of writing a guide, the start of which is here, and may not be currently 100% accurate, but it's here: https://github.com/JobJob/Interact.jl/blob/88e3be64f3d83a4e63753cc4d34902de3866721b/doc/dev%20guide.md

I'll actually just clean it up in the next half-hour so it's accurate for the state of my latest jbj/widget-sig-init branch (the file-upload branch is ahead of that but no major changes there).

A good place to start for how to add new widgets would be to look at the changes I made in the last (only) commit of that file-upload branch.

@JobJob
Copy link
Member

JobJob commented Dec 9, 2016

Yes, re your specific q, that's basically correct. We aren't writing any widgets js or html, just sending messages that create and update the widget, and receiving some with updates to widget's state as a result of user actions.

@JobJob
Copy link
Member

JobJob commented Dec 9, 2016

OK sorry, the links were giving me some pain, but finally cleaned it up, it's a bit raw, but hopefully somewhat useful. I merged it with the file-upload branch to make things easier: https://github.com/JuliaLang/Interact.jl/blob/jbj/file-upload/doc/dev%20guide.md

@piever
Copy link
Collaborator

piever commented Jul 11, 2018

Latest (unreleased) Interact has a filepicker but while it works very well in Electron, in the browser there's this issue that you don't have access to the local file system. I'd be happy to work on getting a working WebIO based solution for a file uploader in the notebook for local use, but am a bit unsure on how to proceed... Does anybody now what exactly the python solution is doing under the hood?

@JobJob
Copy link
Member

JobJob commented Jul 11, 2018

Says here it uses the FileReader api to get the contents of the file in base64 in the browser. Then I think it can sync that to the server.

Code to read the file is here: https://github.com/peteut/ipython-file-upload/blob/master/fileupload/static/widget.js#L46

python code: https://github.com/peteut/ipython-file-upload/blob/master/fileupload/widget.py

@piever
Copy link
Collaborator

piever commented Jul 11, 2018

Thanks for the info, I'll give it a shot in the next few days.

@piever piever self-assigned this Jul 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants