tillahoffmann / obsidian-jupyter

MIT License
438 stars 23 forks source link

Feature request: add input support? #32

Closed Rainbell129 closed 1 year ago

Rainbell129 commented 2 years ago

Dear dev, thanks for the wonderful plugin! It really makes my note-taking so much easier!

Do you plan to perhaps upgrade the jupyter to accept input from users? Not sure if it's feasible, but surely it'll be useful too!

tillahoffmann commented 2 years ago

Hi @Rainbell129, I don't quite follow the request, unfortunately. What sort of input would you like to provide? Do you mean the python input method?

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

Trikzon commented 2 years ago

Hi, I'm not the original issue author, but I think I have the same problem that the original author had.

When using the python input method, I get the following error:

StdinNotImplementedError                  Traceback (most recent call last)
Input In [1], in <cell line: 63>()
     59         else:
     60             print('Error: choice should never not be 1, 2, or 3.')
---> 63 main()

Input In [1], in main()
     33 while True:
     34     print_menu()
---> 36     choice = int(input('Enter your choice: '))
     38     if choice < 1 or choice > 4:
     39         print('That is an invalid option.')

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ipykernel/kernelbase.py:1073, in Kernel.raw_input(self, prompt)
   1066 """Forward raw_input to frontends
   1067 
   1068 Raises
   1069 ------
   1070 StdinNotImplementedError if active frontend doesn't support stdin.
   1071 """
   1072 if not self._allow_stdin:
-> 1073     raise StdinNotImplementedError(
   1074         "raw_input was called, but this frontend does not support input requests."
   1075     )
   1076 return self._input_request(
   1077     str(prompt),
   1078     self._parent_ident["shell"],
   1079     self.get_parent("shell"),
   1080     password=False,
   1081 )

StdinNotImplementedError: raw_input was called, but this frontend does not support input requests.

I am using obsidian-jupyter to put my programming class assignments into Obsidian and the input method is key to almost every assignment.

Is it possible for the python input method to be implemented?

tillahoffmann commented 2 years ago

Hey, despite the apparent simplicity of input in the python terminal/notebook, implementing it would require substantial architectural changes. The plugin currently sends code to a Jupyter kernel, the kernel executes the code and sends back the result. The input method would require additional communication. Having said that, open to contributions!

Trikzon commented 2 years ago

I'm probably too unfamiliar to implement that myself, but it would be cool to see someone take it up.

However, would it be easier if we could give the code predefined input? Something like:

Hello World
42
print('Input:', input() + '!')
print('The answer to life:', int(input())')

I'd imagine that this wouldn't require as many "architectural changes" as you should be able to send the code to the Jupyter kernel all at once with the input. However, I don't have experience with Jupyter so I'm not sure this is feasible.