file-browser dialog implementation

3,409 views
Skip to first unread message

kgeor...@gmail.com

unread,
Jul 31, 2016, 5:43:29 AM7/31/16
to Project Jupyter
Hi,

I would like to implement a file browser dialog in a jupyter notebook.

ie: when some widget button is pressed a file-browser dialog pops up over the browser, and the user selects a file.

I have tried a few methods so far, but I am not satisfied with any of these

1)
I have tried it with a pure javascript/html code using the construct  <input type="file">.  But using this method I can get just the name of the file selected. not even the relative path, or let alone the absolute path of the file.

2)
I have implemented a solution using PySide, a python binding for QT. Using this solution, I can get the file path. But QT brings a whole lot of baggage to software which I would like to avoid.

3)
Is there a node-js based solution, Is there any sample code for such a file-browser?
I took a look at https://github.com/jupyter-attic/jupyter-js-ui. But I am having a hard time trying to come up with some working version of sample code.

-thanks
-koshy


Hai Nguyen

unread,
Jul 31, 2016, 12:49:01 PM7/31/16
to jup...@googlegroups.com
On Sun, Jul 31, 2016 at 5:43 AM, <kgeor...@gmail.com> wrote:
Hi,

I would like to implement a file browser dialog in a jupyter notebook.

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/8b313f6e-4a56-4f1c-bd90-b41993be9e9f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kgeor...@gmail.com

unread,
Aug 2, 2016, 2:52:10 AM8/2/16
to Project Jupyter
Hi Hai,

Thanks for responding. I tried the 'File Upload WIdget' example mentioned here. Unfortunately an html5/js based file-browser would still not give me the relative path or absolute path of the selected file. I don't want to load the file. I just need to get the path of the select the file.


I also tried the file-browser example mentioned in https://github.com/jupyter-attic/jupyter-js-ui .
I did the  'npm build' commands, and 'cd'-ed to the 'examples/filebrowser' directory, and did 'python main.py'
I am able to get the files listed in a web-page as shown below.




 But I want to show them in a pop-up window

-thanks
-koshy

Auto Generated Inline Image 1

Hai Nguyen

unread,
Aug 2, 2016, 1:11:36 PM8/2/16
to jup...@googlegroups.com
On Tue, Aug 2, 2016 at 2:52 AM, <kgeor...@gmail.com> wrote:
Hi Hai,


Thanks for responding. I tried the 'File Upload WIdget' example mentioned here. Unfortunately an html5/js based file-browser would still not give me the relative path or absolute path of the selected file. I don't want to load the file. I just need to get the path of the select the file.


I am not sure if you can even do that in Javascript (for security reason).

Hai
 

Thomas Kluyver

unread,
Aug 2, 2016, 1:18:48 PM8/2/16
to Project Jupyter
On 2 August 2016 at 18:11, Hai Nguyen <nha...@gmail.com> wrote:
I am not sure if you can even do that in Javascript (for security reason).

As far as I know you cannot get the path of a file directly in Javascript. You would have to make a file picker that communicates with the server to list directory contents and create a path.

Matthias Bussonnier

unread,
Aug 2, 2016, 4:46:36 PM8/2/16
to jup...@googlegroups.com
I think there is a deeper question,

Are you trying to get a file path for which machine :
- The machine that host the kernel, and I guess relative to the
kernel cwd (a)
- The machine that host the server and relative to the notebook
location on the server (b)
- the user web browser (c), [not sure relative to what]

Even if these 3 are potentially on the same machine, the possibilities
are different, the meaning are different, and from previous discussion
you seem to not really see the difference.
Widgets and QT provides (a), <input type="file"> provides (c) , and
https://github.com/jupyter-attic/jupyter-js-ui. provide (b).

You need to define clearly which use case you want to get a clear answer.

--
M
> --
> You received this message because you are subscribed to the Google Groups
> "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jupyter+u...@googlegroups.com.
> To post to this group, send email to jup...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jupyter/CAOvn4qgYPvErNLGETxgydc7i3LN5LG%2Bw-%2BLUPCMK%2B9Fq6%2BvFWQ%40mail.gmail.com.

kgeor...@gmail.com

unread,
Aug 4, 2016, 7:30:56 PM8/4/16
to Project Jupyter
Hi Matthias,

thanks for the reply.

>> The machine that host the kernel, and I guess relative to the 
kernel cwd (a) 
>> The machine that host the server and relative to the notebook 
location on the server (b) 
>> The user web browser (c)


I would rather have (a) or (b).  It doesnot make a difference for me, since my kernel and server are in the same machine.
I have tried  QT based solution and  is a very clunky solution.

I tried using the jupyter-js-ui solution. So far I have been able to show the file browser in a webpage. But I need to make it appear as a pop-up dialog.
Is there any pointers for that.





















-thanks
-koshy

kgeor...@gmail.com

unread,
Aug 4, 2016, 10:18:59 PM8/4/16
to Project Jupyter
Regarding the Qt based solution for file-browser

0)
I 'ssh -X' to my dev station from my pc. All the activity is happening in my dev station.


1)
when I run my note-book with jupyter, I press a button and it expectedly  which launches a pop-up  file-browser dialog.

2)
But when I run jupyter-hub and use python 2.7 kernel to run my notebook,
I press the button and  the kernel dies with the error message "Cannot connect to X-server".
Attached is the log for running jupyter-hub. Only the starting log is shown, which shows how I may have started it.

-thanks
-koshy
jupyter-hub-log.txt
Reply all
Reply to author
Forward
0 new messages