I have a file reading from spark i have to get the data in a variable and show the datatable… and i showed the data by data preview, Now i have to make it partition, so i want to give the value in box with submit button…
here i the sample code for data preview but i need to specify the partition.Help me…
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
import pandas as pd
from pyspark.sql import SparkSession
from pyspark.context import SparkContext
sc= SparkContext.getOrCreate()
spark = SparkSession.builder .master(“spark://sparkmaster:7077”) .appName(“My Spark Application”) .config(“spark.submit.deployMode”, “client”) .getOrCreate()
app = dash.Dash()
external_stylesheets = [‘https://codepen.io/chriddyp/pen/bWLwgP.css’]
data = sc.textFile(“hdfs://master:9000/suhail/oneminstock.csv”,4)
data.getNumPartitions()
type(data)
sparkDF = data.map(lambda x: str(x)).map(lambda w: w.split(’,’)).toDF()
df = sparkDF.toPandas()
type(df)
df
Ticker = list(set(df._1))
len(Ticker)
Ticker
df1=df[df._1==‘KSERASERA.NSE’]
df1
app = dash.Dash(name, external_stylesheets=external_stylesheets)
app.layout = html.Div([
dcc.Dropdown(id=‘dropdown’, options=[
{‘label’: i, ‘value’: i} for i in df._1.unique()
], placeholder=‘Filter by Sectors’),
html.Div(id=‘table-container’),
dcc.Input(id=‘input-1-state’, type=‘text’, value=‘2’),
html.Button(id=‘submit-button’, n_clicks=0, children=‘Submit’),
html.Div(id=‘output-state’)
])
@app.callback(Output(‘output-state’, ‘children’),
[Input(‘submit-button’, ‘n_clicks’)],
[State(‘input-1-state’, ‘value’)])
def update_output(n_clicks, input1 ):
return u’’’
The number of partitions given {}
‘’’.format(n_clicks, input1)
def generate_table(dataframe, max_rows=10):
return html.Table(
# Header
[html.Tr([html.Th(col) for col in dataframe.columns])] +
# Body
[html.Tr([
html.Td(dataframe.iloc[i][col]) for col in dataframe.columns
]) for i in range(min(len(dataframe), max_rows))]
)
@app.callback(
dash.dependencies.Output(‘table-container’, ‘children’),
[dash.dependencies.Input(‘dropdown’, ‘value’)])
def display_table(dropdown_value):
if dropdown_value is None:
return generate_table(df)
dff = df[df._1.str.contains(dropdown_value)]
return generate_table(dff),
if name == ‘main’:
app.run_server(debug=True)