So I have stock prices of 5 companies. What I am trying to do is use a dropdown menu to select the company and create a line plot using data for the company selected from the dropdown menu. The code I have so far is as below :
import pandas as pd
intel = pd.read_csv(r'C:\Users\PC\Desktop\INTEL.csv')
nvidia = pd.read_csv(r'C:\Users\PC\Desktop\NVIDIA.csv')
amd = pd.read_csv(r'C:\Users\PC\Desktop\AMD.csv')
gigabyte = pd.read_csv(r'C:\Users\PC\Desktop\GIGABYTE.csv')
msi= pd.read_csv(r'C:\Users\PC\Desktop\MSI.csv')
stocks= widgets.Dropdown(
description='Stocks: ',
options=['','Intel','Nvidia','AMD','Gigabyte','MSI']
)
name = stock.value
def response(name):
if name=='Intel' :
Intel_chart = go.Line(x=Intel['Date'],y=Intel['Close'])
Intel_data = [Intel_chart]
iplot(Intel_data)
elif name=='Nvidia' :
Nvidia_chart = go.Line(x=Nvidia['Date'],y=Nvidia['Close'])
Nvidia_data = [Nvidia_chart]
iplot(Nvidia_data)
elif name=='AMD' :
AMD_chart = go.Line(x=AMD['Date'],y=AMD['Close'])
AMD_data = [AMD_chart]
iplot(AMD_data)
elif name=='Gigabyte' :
Gigabyte_chart = go.Line(x=Gigabyte['Date'],y=Gigabyte['Close'])
Gigabyte_data = [Gigabyte_chart]
iplot(Gigabyte_data)
elif name=='MSI' :
MSI_chart = go.Line(x=MSI['Date'],y=MSI['Close'])
MSI_data = [MSI_chart]
iplot(MSI_data)
However, the plots are not showing up when I choose the a value from the dropdown menu. What am i doing wrong? I have used Plotly before to plot the charts but I am new to ipywidgets and so any and all help will be appreciated.
Thanks in advance