Quería crear un sitio web e incorporar la funcionalidad del cuaderno jupyter de poder crear celdas y ejecutar el código python dentro de mi sitio web.
Para crear un sitio web, estoy usando Django y me gustaría incrustar Google Collab o Jupyter Notebook.
Por cierto, he investigado lo suficiente y me he quedado atascado con los enlaces de StackOverflow donde no hay respuesta sobre esto o sobre el que quieren usar django en jupyter notebook.
Gracias de antemano por cualquier orientación o cualquier referencia que puedan proporcionar.
Nota: Usé "jupyter-lab", puedes usar "jupyter notebook"
1- La primera opción para redirigir a "cuaderno jupyter"
django view.py
from django.shortcuts import redirect,HttpResponse import subprocess import time def open_jupiter_notbook(request): b= subprocess.check_output("jupyter-lab list".split()).decode('utf-8') if "9999" not in b: a=subprocess.Popen("jupyter-lab --no-browser --port 9999".split()) start_time = time.time() unreachable_time = 10 while "9999" not in b: timer = time.time() elapsed_time = timer-start_time b= subprocess.check_output("jupyter-lab list".split()).decode('utf-8') if "9999" in b: break if elapsed_time > unreachable_time: return HttpResponse("Unreachable") path = b.split('\n')[1].split('::',1)[0] #You can here add data to your path if you want to open file or anything return redirect(path)si desea implementarlo en la plantilla en lugar de redirigir, puede usar el siguiente código en la plantilla de Django:
<iframe src="{% url 'open_jupiter_notbook' %}" width= 600px height=200px></iframe>2- La segunda opción:
simplemente use los comandos de jupyter notebook usando este subprocess.check_output("your command".split())