Originally posted on pythonanywhere forum, but was told to post it here:
I have written a number of interactive jupyter notebooks (using ipywidgets and matplotlib). Is there a tutorial on how to host these as webapps on pythonanywhere so students can use them as a learning tool? Thanks. (Very new to webapps, so the most basic tutorial is appreciated).
Here is a sample notebook code.
import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import interact
# Function to update the plot
def update_plot(frequency):
plt.clf() # Clear the current figure
x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(frequency * x)
plt.plot(x, y)
plt.title(f'Sine Wave with Frequency: {frequency}')
plt.xlabel('x')
plt.ylabel('sin(frequency * x)')
plt.ylim(-1.5, 1.5)
plt.grid()
plt.show()
# Create a slider for frequency
frequency_slider = interact(update_plot, frequency=(1, 10, 0.1))
from ipywidgets import widgets
slider = widgets.IntRangeSlider(value=[10,15], min = 0, max=30, continuous_update=True)
outbox = widgets.Output()
with outbox:
print(f"Start Value: \t{slider.value[0]}\nEnd Value: \t{slider.value[1]}")
display(slider,outbox)
def updateVals(change):
with outbox:
outbox.clear_output()
print(f"Start Value: \t{slider.value[0]}\nEnd Value: \t{slider.value[1]}")
slider.observe(updateVals)
BTW, I used anaconda assistant to tell me how I can turn my notebook into a webapp, but it does not work. I just need simple instructions/tutorial on how to turn the code below into a webapp.