Skip to content

Instantly share code, notes, and snippets.

import {
Streamlit,
StreamlitComponentBase,
withStreamlitConnection
} from "streamlit-component-lib";
import { ReactNode} from "react";
class MainComponent extends StreamlitComponentBase {
public render = (): ReactNode => {
@Chico-Chen
Chico-Chen / weighted.py
Last active April 1, 2021 12:57
streamlit react
import streamlit.components.v1 as components
def weighted_path(conn, country):
country = country.drop([0]).reset_index(drop=True)
country = country.to_string(index=False)
_map_compoent = components.declare_component("United States", url="http://localhost:3000")
component_value=_map_compoent(name="weighted", key=country)
@Chico-Chen
Chico-Chen / set_chart.py
Created April 1, 2021 01:17
hackathon graph centrality
def set_chart(data):
bars = alt.Chart(data).mark_bar().encode(
x = alt.X('sum(score):Q', stack='zero'),
y = alt.Y('name:N', sort='-x'),
color = alt.Color('centrality'),
tooltip='score',
).properties(
width=1000
)
return bars
@Chico-Chen
Chico-Chen / overall_chart.py
Created April 1, 2021 01:15
graph centrality
def combine_data(source, idx, res, cent_name):
for i in range(len(source)):
name = source.loc[i, 'name']
score = source.loc[i, 'score']
centrality = cent_name
res.loc[idx] = [name, score, centrality]
idx += 1
return res, idx
def overall_chart(bc, cc, dc, pr):
import pydeck as pdk
import streamlit as st
def set_map(data):
st.pydeck_chart(pdk.Deck(
map_style="mapbox://styles/mapbox/light-v9",
initial_view_state=pdk.data_utils.compute_view(data[['lng','lat']]),
tooltip={"text": "{Vertex_ID}\n{name}"},
layers=[
pdk.Layer(
def degreeCentrality(conn, country):
if (country == "None"):
return
params = "country=" + country
# conn.debug = True
res = conn.runInstalledQuery('dc_by_country', params=params, timeout=16000)
res = pd.DataFrame(res[0]["@@topScores"])
return res
import 'package:flutter/material.dart';
class Answer extends StatelessWidget {
final Function selectHandler;
final String answerText;
Answer(this.selectHandler, this.answerText);
@override
Widget build(BuildContext context) {
import 'package:flutter/cupertino.dart';
class Question extends StatelessWidget {
final String questionText;
Question(this.questionText) {}
@override
Widget build(BuildContext context) {
// container take full size of screen now
import 'package:flutter/material.dart';
class Result extends StatelessWidget {
final int resultScore;
final Function resetHandler;
Result(this.resultScore, this.resetHandler);
String get resultPhrase {
String resultText;
import 'package:flutter/material.dart';
import './question.dart';
import './answer.dart';
class Quiz extends StatelessWidget {
final List<Map<String, Object>> questions;
final int questionIndex;
final Function answerQuestion;