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

Support for Jupyter notebooks #86

Open
ahuang11 opened this issue May 19, 2024 · 12 comments
Open

Support for Jupyter notebooks #86

ahuang11 opened this issue May 19, 2024 · 12 comments
Assignees

Comments

@ahuang11
Copy link

Wondering if it's possible to run in notebook, or at least indirectly.

In Panel, there's panel_obj.show() which opens a new browser.

@forrestbao
Copy link
Member

Thanks @ahuang11 for this suggestion. We heard the same feature request from many others at PyCon US 2024.

What's your suggestion on how a user can trigger the code-to-app conversion?
As you know, Funix does not require the user to modify the code. So how can Jupyter know when is the time to map the user code to a GUI app?
By adding a magic command and display the app when pressing Ctrl/Cmd + Enter?
Or, by using a new button on Jupyter?

@ahuang11
Copy link
Author

A decorator probably?

@funix
def ...

Or magic command works too I guess, but I like decorator

%funix

def ...

@forrestbao
Copy link
Member

Thanks. I am sitting on the fence between the two options. I feel the magic command is more a Juypte-way of doing things. The downside is that if you want to save the code from Jupyter cells to regular Python scripts, you need to comment out the magic commands.

@ahuang11
Copy link
Author

ahuang11 commented May 21, 2024

Perhaps the most Jupyter way of doing things is if the function is on the last line. If it is, display it.

i.e.

def hello(your_name: str) -> str:
    return f"Hello, {your_name}."

hello

@forrestbao
Copy link
Member

Thanks. We will support at least one way to do it first. Then we can support more.

@Yazawazi
Copy link
Collaborator

On the develop branch, there is a way to run Funix indirectly in Jupyter:

from funix import funix


@funix()
def hello(a: str) -> str:
    return f"Hello {a}!"

This will directly open a new Flask application and show this by iframe.

Image

In the future, I will try to communicate with the kernel for calling functions.

The following is a reference steps for using funix with the develop branch:

  1. git clone https://github.com/TexteaInc/funix
  2. cd funix
  3. git checkout develop
  4. pip install -e .

@ahuang11
Copy link
Author

ahuang11 commented May 21, 2024

Cool, quick update!

I'm wondering if it's possible to, separately, import funix.notebook once at an upper cell, and all subsequent cells will automatically show iframe if there's the function variable at the end?

Cell 1

import funix.notebook

Cell 2

def hello(a: str) -> str:
    return f"Hello {a}!"

hello

@Yazawazi
Copy link
Collaborator

I'll try to work on this idea 👀

@Yazawazi Yazawazi self-assigned this May 21, 2024
@forrestbao
Copy link
Member

I am not sure about this idea below because it conflicts with expectations per Jupyter convention.
A user's expectation for the last line, hello is printing the variable hello, which here will be the location in the RAM of the function.

What do you guys think?

Cool, quick update!

I'm wondering if it's possible to, separately, import funix.notebook once at an upper cell, and all subsequent cells will automatically show iframe if there's the function variable at the end?

Cell 1

import funix.notebook

Cell 2

def hello(a: str) -> str:
    return f"Hello {a}!"

hello

@ahuang11
Copy link
Author

ahuang11 commented May 21, 2024

which here will be the location in the RAM of the function.

I personally have never utilized the location in the RAM of the function. Also, if they really need it, print(hello) would return that.

Alternatively, I think you could inject a method on all functions like:

hello.servable() or hello.funix() to make it show, depending on whether you want users to modify their code.

Also, Jupyter conventions I think, more accurately, displays the variable in a pretty format e.g.

image

@forrestbao
Copy link
Member

The expected behavior is as follows:

In [1]: def hello(a: str) -> str:
   ...:     return "Hello, " + a + "!"
   ...: 

In [2]: hello
Out[2]: <function __main__.hello(a: str) -> str>

In [3]: print(hello)
<function hello at 0x70565a7a2320>

@ahuang11
Copy link
Author

Yes, I think display(hello) results in <function __main__.hello(a: str) -> str>

image

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