0 Daumen
39 Aufrufe

Ich habe ein Suchmaschine, die ein Array von artikeln zuruckgibt, die einen Artikel enthalten.

Ich möchte Ihnen jedoch noch ein wenig mehr Twitter-Newsfeed-Design  geben. Ich wurde gerne darauf klicken und es erklaren konnen.

Hier ist der Ruckruk des Browsers:

from dash.dependencies import Input, Output, State
import dash_core_components as dcc

import pickle

from ..server import app

@app.callback(
    Output('output-container-button', 'children'),
    [Input('button', 'n_clicks')],
    [State('input-box', 'value')])
def update_search(n_clicks, value):
    f = pickle.load(open("dashboard/data-mm/google-nlu.p", "rb"))
    # let's filter f according to value
    articles = []
    for article in f:
        if value in article['headline']:
            # We want to print this
            articles.append(article)
    print(articles[0])
    return dcc.Markdown([f"{article['headline']}\n" for article in articles])

Und hier ist app.py

app.layout = html.Div(
    [
        dcc.Tabs(
            [
                dcc.Tab(
                    label='Search article',
                    value= 'search',
                    children = article_search()
                )
            ]
        )
    ]
)
Im Moment sieht es so aus:

dashboard_search.png

Jede schwarze Linie ist ein article['headline']

Hier is ein Artikel, articles[0]:

{'headline': this is the headline', 'body': 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.', 'sentiment': -0.4000000059604645, 'topics': {'/Finance': 0.6600000262260437}, 'topics_kw': ['Politics', 'The financial sector', 'Media', 'Society', 'Social projects'], 'date': datetime.datetime(2019, 9, 25, 0, 0)}

von

Ein anderes Problem?

Stell deine Frage

Willkommen bei der Stacklounge! Stell deine Frage sofort und kostenfrei

x
Made by a lovely community