File size: 1,872 Bytes
143b0d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using Dash
using DataFrames
using PlotlyJS

# Sample data for demonstration
df = DataFrame(
    text = ["Example text $i" for i in 1:10],
    classification = ["Misinformation", "Legitimate", "Misinformation", "Legitimate", "Misinformation", "Legitimate", "Misinformation", "Legitimate", "Misinformation", "Legitimate"],
    score = rand(0:100, 10)
)

app = dash()

app.layout = html_div() do
    [
        dcc_input(id="search-box", type="text", placeholder="Enter text to search for", style=Dict("width" => "100%")),
        html_button("Search", id="search-button", n_clicks=0),
        dash_datatable(
            id="results-table",
            columns=[Dict("name" => i, "id" => i) for i in names(df)],
            data=Dict.(pairs.(eachrow(df))),
            row_selectable="multi",
            selected_rows=[]
        ),
        dcc_graph(id="score-distribution")
    ]
end

callback!(
    app,
    Output("results-table", "data"),
    Output("score-distribution", "figure"),
    Input("search-button", "n_clicks"),
    State("search-box", "value")
) do n_clicks, search_value
    if n_clicks > 0 && !isempty(search_value)
        filtered_data = filter(row -> occursin(search_value, row.text), df)
        data_dict = Dict.(pairs.(eachrow(filtered_data)))
        
        scores = filtered_data[!, :score]
        fig = plot(
            bar(x=1:length(scores), y=scores, marker_color="blue"),
            Layout(title="Score Distribution", xaxis_title="Index", yaxis_title="Score")
        )
        
        return data_dict, fig
    else
        empty_data = Dict.(pairs.(eachrow(DataFrame())))
        empty_fig = plot(
            bar(x=[], y=[], marker_color="blue"),
            Layout(title="Score Distribution", xaxis_title="Index", yaxis_title="Score")
        )
        return empty_data, empty_fig
    end
end

run_server(app, "0.0.0.0", debug=true)