How to display data-table on a Web page using in python using DASH framework?


2 weeks ago


5 time


I have written my code with an intention of displaying a table in a Web page. However, my current result is coming from console so far but i would like to view from a Web page.

Below is what i have tried

app.layout = dash_table.DataTable(
    columns=[{"name": i, "id": i} for i in df.columns],

    output=Output('my-table', 'table'),
def make_dash_table(df):

    ''' Return a dash definitio of an HTML table for a Pandas dataframe '''
    metadata = pd.read_csv('ratings.csv', low_memory=False)
    # Calculate C
    C = metadata['rating_average'].mean()
    # Calculate the minimum number of votes required to be in the chart, m
    m = metadata['rating_count'].quantile(0.90)
    # Filter out all qualified movies into a new DataFrame
    q_movies = metadata.copy().loc[metadata['rating_count'] >= m]

    def weighted_rating(x, m=m, C=C):
        v = x['rating_count']
        R = x['rating_average']
        # Calculation based on the IMDB formula
        return (v / (v + m) * R) + (m / (m + v) * C)

    # Define a new feature 'score' and calculate its value with `weighted_rating()`
    q_movies['score'] = q_movies.apply(weighted_rating, axis=1)
    # Sort movies based on score calculated above
    q_movies = q_movies.sort_values('score', ascending=False)

    # Print the top 15 movies
    eta= q_movies[['Product_Name', 'rating_count', 'rating_average', 'score']].head(15)

    return eta

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

The code should return a table in a Web page

0 answers