Spaces:
Sleeping
Sleeping
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) |