TypeError: string indices must be integers

Hi friends.
My code is

import dash
import dash_html_components as html
import dash_core_components as dcc
import plotly.graph_objs as go
import pandas as pd
from plotly import tools


external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.scripts.config.serve_locally=True
server = app.server

data_2019 = pd.read_csv('data_2019.csv', sep=';')
df_2019_based_on_leads = data_2019[data_2019['Лиды/Всего']>0] # ЛИДЫ БОЛЬШЕ 0

def create_table(currency):
	eur_df_2019_based_on_leads = df_2019_based_on_leads[df_2019_based_on_leads['Валюта']==currency] # ТОЛЬКО В ЕВРО
	eur_df_2019_based_on_leads_revenue = eur_df_2019_based_on_leads[['Дата','ID Партнера','Доходы']]
	eur_df_2019_based_on_leads_revenue = eur_df_2019_based_on_leads_revenue[ 
	    eur_df_2019_based_on_leads_revenue['Доходы']>0].groupby(['ID Партнера','Дата']
	    	)['Доходы'].sum().reset_index() # ПЕРЕФОРМАТИРОВАНИЕ ПОД ДОХОД

	return eur_df_2019_based_on_leads_revenue



def tops_wm(currency):
	df = create_table(currency)
	tops = df.groupby('ID Партнера')['Доходы'].sum().sort_values(ascending=False).reset_index()
	return tops


eur_df = pd.pivot_table(create_table('EUR'),
	index='Дата',
	values='Доходы',
	columns='ID Партнера',
	fill_value=0)
pln_df = pd.pivot_table(create_table('PLN'),
	index='Дата',
	values='Доходы',
	columns='ID Партнера',
	fill_value=0)
usd_df = pd.pivot_table(create_table('USD'),
	index='Дата',
	values='Доходы',
	columns='ID Партнера',
	fill_value=0)
mxn_df = pd.pivot_table(create_table('MXN'),
	index='Дата',
	values='Доходы',
	columns='ID Партнера',
	fill_value=0)
eur_top = tops_wm('EUR')
pln_top = tops_wm('PLN')
usd_top = tops_wm('USD')
mxn_top = tops_wm('MXN')

traces1 = []
traces2 = []
traces3 = []
traces4 = []

def generate_data_for_graph(selected_top_count):
	e_columns = eur_top.iloc[selected_top_count[0]:selected_top_count[1]+1]['ID Партнера'].values
	p_columns = pln_top.iloc[selected_top_count[0]:selected_top_count[1]+1]['ID Партнера'].values
	u_columns = usd_top.iloc[selected_top_count[0]:selected_top_count[1]+1]['ID Партнера'].values
	m_columns = mxn_top.iloc[selected_top_count[0]:selected_top_count[1]+1]['ID Партнера'].values
	e_df = eur_df[e_columns]
	p_df = pln_df[p_columns]
	u_df = usd_df[u_columns]
	m_df = mxn_df[m_columns]
	for i in e_df.columns:
		traces1.append(go.Scatter(
			x=e_df.index,
	    	y=e_df[i].values,
	    	name=str(i)
		))
	for i in p_df.columns:
		traces2.append(go.Scatter(
			x=p_df.index,
	    	y=p_df[i].values,
	    	name=str(i)
		))
	for i in u_df.columns:
		traces3.append(go.Scatter(
			x=p_df.index,
	    	y=p_df[i].values,
	    	name=str(i)
		))
	for i in m_df.columns:
		traces4.append(go.Scatter(
			x=m_df.index,
	    	y=m_df[i].values,
	    	name=str(i)
		))
	data = tools.make_subplots(rows=3, cols=1)
	data.append_trace(traces4, 1, 1)
	data.append_trace(traces3, 1, 1)
	data.append_trace(traces2, 2, 1)
	data.append_trace(traces1, 3, 1)
	return data

app.layout = html.Div([
	html.Div(id='EUR'[dcc.Graph(id='graph'), # ВЫВОД ГРАФИКА
		dcc.RangeSlider(
			id='tops',
			min=0,
			max=10, # eur_top.index.max(),
			value=[0,0],
			# marks={i: 'Топ: {}'.format(i+1) for i in eur_top.index}
		)
	])
	
])

@app.callback(
    dash.dependencies.Output('graph', 'figure'),
    [dash.dependencies.Input('tops', 'value')])
def update_figure(selected_top_count):
	generate_data_for_graph(selected_top_count)

	return {
		'data': data
		# 'layout': go.Layout(
		# 		title='US Export of Plastic Scrap',
        #     	showlegend=True,
        #     	legend=go.layout.Legend(
        #         	x=0,
        #         	y=1.0
        #     	),
        #     	margin=go.layout.Margin(l=40, r=40, t=40, b=30)
        # 	)
	}

if __name__ == '__main__':
    app.run_server(debug=True)

i’m getting error:

"Traceback (most recent call last):
  File "try_graphs.py", line 159, in <module>
    value=[0,0],
TypeError: string indices must be integers

I cant find the problem, coz wen i do the same code without functions - i dont get this error. And i need this functions.
What am i doing wrong?

This code works fine:

import dash
import dash_html_components as html
import dash_core_components as dcc
import plotly.graph_objs as go
import pandas as pd


external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.scripts.config.serve_locally=True
server = app.server

data_2019 = pd.read_csv('data_2019.csv', sep=';')

# НЕ УДАЕТСЯ ПЕРЕВЕСТИ В ФУНКЦИЮ
df_2019_based_on_leads = data_2019[data_2019['Лиды/Всего']>0] # ЛИДЫ БОЛЬШЕ 0

eur_df_2019_based_on_leads = df_2019_based_on_leads[df_2019_based_on_leads['Валюта']=='EUR'] # ТОЛЬКО В ЕВРО
eur_df_2019_based_on_leads_revenue = eur_df_2019_based_on_leads[['Дата','ID Партнера','Доходы']]
eur_df_2019_based_on_leads_revenue = eur_df_2019_based_on_leads_revenue[ 
eur_df_2019_based_on_leads_revenue['Доходы']>0].groupby(['ID Партнера','Дата']
	)['Доходы'].sum().reset_index() # ПЕРЕФОРМАТИРОВАНИЕ ПОД ДОХОД
pivoted_eur_df_2019_based_on_leads_revenue = pd.pivot_table(eur_df_2019_based_on_leads_revenue,
                                                       index='Дата',
                                                       values='Доходы',
                                                       columns='ID Партнера',
                                                       fill_value=0)
eur_tops = eur_df_2019_based_on_leads_revenue.groupby('ID Партнера')['Доходы'].sum().sort_values(
	ascending=False).reset_index()

pln_df_2019_based_on_leads = df_2019_based_on_leads[df_2019_based_on_leads['Валюта']=='PLN'] # ТОЛЬКО В ЕВРО
pln_df_2019_based_on_leads_revenue = pln_df_2019_based_on_leads[['Дата','ID Партнера','Доходы']]
pln_df_2019_based_on_leads_revenue = pln_df_2019_based_on_leads_revenue[ 
pln_df_2019_based_on_leads_revenue['Доходы']>0].groupby(['ID Партнера','Дата']
	)['Доходы'].sum().reset_index() # ПЕРЕФОРМАТИРОВАНИЕ ПОД ДОХОД
pivoted_pln_df_2019_based_on_leads_revenue = pd.pivot_table(pln_df_2019_based_on_leads_revenue,
                                                       index='Дата',
                                                       values='Доходы',
                                                       columns='ID Партнера',
                                                       fill_value=0)
pln_tops = pln_df_2019_based_on_leads_revenue.groupby('ID Партнера')['Доходы'].sum().sort_values(
	ascending=False).reset_index()

usd_df_2019_based_on_leads = df_2019_based_on_leads[df_2019_based_on_leads['Валюта']=='USD'] # ТОЛЬКО В ЕВРО
usd_df_2019_based_on_leads_revenue = usd_df_2019_based_on_leads[['Дата','ID Партнера','Доходы']]
usd_df_2019_based_on_leads_revenue = usd_df_2019_based_on_leads_revenue[ 
usd_df_2019_based_on_leads_revenue['Доходы']>0].groupby(['ID Партнера','Дата']
	)['Доходы'].sum().reset_index() # ПЕРЕФОРМАТИРОВАНИЕ ПОД ДОХОД
pivoted_usd_df_2019_based_on_leads_revenue = pd.pivot_table(usd_df_2019_based_on_leads_revenue,
                                                       index='Дата',
                                                       values='Доходы',
                                                       columns='ID Партнера',
                                                       fill_value=0)
usd_tops = usd_df_2019_based_on_leads_revenue.groupby('ID Партнера')['Доходы'].sum().sort_values(
	ascending=False).reset_index()

mxn_df_2019_based_on_leads = df_2019_based_on_leads[df_2019_based_on_leads['Валюта']=='MXN'] # ТОЛЬКО В ЕВРО
mxn_df_2019_based_on_leads_revenue = mxn_df_2019_based_on_leads[['Дата','ID Партнера','Доходы']]
mxn_df_2019_based_on_leads_revenue = mxn_df_2019_based_on_leads_revenue[ 
mxn_df_2019_based_on_leads_revenue['Доходы']>0].groupby(['ID Партнера','Дата']
	)['Доходы'].sum().reset_index() # ПЕРЕФОРМАТИРОВАНИЕ ПОД ДОХОД
pivoted_mxn_df_2019_based_on_leads_revenue = pd.pivot_table(mxn_df_2019_based_on_leads_revenue,
                                                       index='Дата',
                                                       values='Доходы',
                                                       columns='ID Партнера',
                                                       fill_value=0)
mxn_tops = mxn_df_2019_based_on_leads_revenue.groupby('ID Партнера')['Доходы'].sum().sort_values(
	ascending=False).reset_index()


app.layout = html.Div([
	# ВКЛАДКИ
html.Div([
    html.H1(id='output-container'),
    dcc.Tabs(id="tabs", children=[
        # ВКЛАДКА ПРИБЫЛЬ
        dcc.Tab(id='profit_tab', label='Прибыль',children=[
        	dcc.Graph(id='eu_graph',style={'height': 300, 'width':1000}),
        	html.Div([dcc.RangeSlider(
					id='eu_tops',
					min=0,
					max=eur_tops.index.max(),
					value=[0,0],
					marks={
						0: {'label': 'Топ 1', 'style': {'color': '#77b0b1'}},
						2: {'label': 'Топ 3'},
						4: {'label': 'Топ 5'},
						9: {'label': 'Топ 10', 'style': {'color': '#f50'}}
					}
				)], style={'margin-top': 50, 'margin-bottom': 20, 'margin-left':40, 'margin-right': 700}),
				dcc.Graph(id='pln_graph',style={'height': 300, 'width':1000}),
				html.Div([
					dcc.RangeSlider(
						id='pln_tops',
						min=0,
						max=pln_tops.index.max(),
						value=[0,0],
						marks={
							0: {'label': 'Топ 1', 'style': {'color': '#77b0b1'}},
							2: {'label': 'Топ 3'},
							4: {'label': 'Топ 5'},
							9: {'label': 'Топ 10', 'style': {'color': '#f50'}}
						}
					)
				], style={'margin-top': 50, 'margin-bottom': 20, 'margin-left':40, 'margin-right': 700})

        ]),
        # ВКЛАДКА ДОХОД
        dcc.Tab(id='revenue_tab', label='Доходы'),
        # ВКЛАДКА EPC
        dcc.Tab(id='EPC_tab', label='EPC'),
        # ВКЛАДКА AR
        dcc.Tab(id='AR_tab', label='AR'),
    ])
])
])

@app.callback(
dash.dependencies.Output('eu_graph', 'figure'),
[dash.dependencies.Input('eu_tops', 'value')])
def update_figure(selected_top_count):
	traces = []
	columns = eur_tops.iloc[selected_top_count[0]:selected_top_count[1]+1]['ID Партнера'].values
	df = pivoted_eur_df_2019_based_on_leads_revenue[columns]
	for i in df.columns:
		traces.append(go.Scatter(
			x=df.index,
	    	y=df[i].values,
	    	name=str(i)
		))
	return {
		'data': traces,
		'layout': go.Layout(
				title='EURO',
        	showlegend=True,
        	legend=go.layout.Legend(
            	x=1.0,
            	y=1.0
        	),
        	margin=go.layout.Margin(l=40, r=40, t=40, b=30)
    	)
	}

@app.callback(
dash.dependencies.Output('pln_graph', 'figure'),
[dash.dependencies.Input('pln_tops', 'value')])
def update_figure(selected_top_count):
	traces = []
	columns = pln_tops.iloc[selected_top_count[0]:selected_top_count[1]+1]['ID Партнера'].values
	df = pivoted_pln_df_2019_based_on_leads_revenue[columns]
	for i in df.columns:
		traces.append(go.Scatter(
			x=df.index,
	    	y=df[i].values,
	    	name=str(i)
		))
	return {
		'data': traces,
		'layout': go.Layout(
				title='PLN',
        	showlegend=True,
        	legend=go.layout.Legend(
            	x=1.0,
            	y=1.0
        	),
        	margin=go.layout.Margin(l=40, r=40, t=40, b=30)
    	)
	}

if __name__ == '__main__':
app.run_server(debug=True)