0

notebook image

mcq_helper.py code

import ipywidgets as widgets
from IPython.display import display
import sys

output = widgets.Output()

if __name__ == '__main__':
    question = sys.argv[1]
    options = sys.argv[2:]
    with output:
        display(widgets.RadioButtons(options=options, description=question))
display(output)

I'm serving jupyterlab from my server. I would like to achieve the following:

  1. Instead of writing %run command in the cell explicitly, I want it to run by default every time a cell is executed.
  2. I want to hide the cell soon as it is executed, and only the output to be visible.

How can I do that?

4
  • Can you address a couple things to clarify? Let's start with second bullet point first. "I want to hide the cell soon as it is executed, and only the output to be visible." Would it be more accurate to say you don't want the code showing at all at any point? And do you need the interface to look like it has cells or not? If the answer to both of those is 'yes', then you might want to look at Voila or Voici. Keep in mind the latter is still in the early development phase. Overall, ... Commented Feb 28 at 15:10
  • <continued> have you seen JupyterQuiz? As for you second bullet point, I think the easiest, more explicit way to do this would be to define a custom magic in an early code cell. And then use that magic in every cell. It would reduce what you have there at least. Alternatively, you an input transformation define in an early cell of your notebook could achieve your goal, see here and the links therein. However, ... Commented Feb 28 at 15:19
  • <continued> because %run or !python wouldn't be allowed (I think), you'd have to change how you trigger mcq_helper.py. Practically since it is small it would be easier to build that into the notebook, or at least import it early in your notebook as a function you can call. Or something along those lines. Commented Feb 28 at 15:23
  • A good resource for custom magics is here. Here is another example. Commented Feb 28 at 15:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.