File size: 2,317 Bytes
762c48d
cf58608
762c48d
 
cf58608
762c48d
 
22eeff0
762c48d
22eeff0
cf58608
762c48d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cf58608
762c48d
 
 
 
 
cf58608
762c48d
cf58608
762c48d
 
cf58608
762c48d
 
 
cf58608
 
762c48d
 
 
 
 
 
 
 
cf58608
 
762c48d
 
22eeff0
762c48d
22eeff0
762c48d
 
 
22eeff0
cf58608
22eeff0
762c48d
 
22eeff0
762c48d
 
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Import panel and vega datasets

import panel as pn
import vega_datasets

# Enable Panel extensions
pn.extension()
template = pn.template.BootstrapTemplate(
    title='SI649 Lab7',
)

# Define a function to create and return a plot
def create_plot(subgroup):
# def create_plot(subgroup, date_range, moving_av_window):

    # Apply any required transformations to the data in pandas)
    filtered_df = df2_approve[df2_approve['subgroup'] == subgroup]
    # filtered_df = filtered_df[(filtered_df['timestamp'] >= date_range[0]) & (filtered_df['timestamp'] <= date_range[1])]
    # filtered_df['Smoothed_Rate'] = filtered_df['rate'].rolling(window=moving_av_window, min_periods=1).mean().shift()

    # Line chart
    # line_chart = alt.Chart(filtered_df).mark_line(color='red').encode(
    #     x='timestamp:T',
    #     y='Smoothed_Rate:Q'
    # )

    # Scatter plot with individual polls
    scatter_plot = alt.Chart(filtered_df).mark_point(color='gray', size=2, opacity=0.7).encode(
        x='timestamp:T',
        y='rate:Q'
    )

    # Put them togetehr
    plot = scatter_plot
    
    # Return the combined chart
    return plot

# date_range = ('2021-04-01', '2023-01-01')

# create_plot('All polls', date_range, 3)
    

# # Create the selection widget
# subgroup_widget = pn.widgets.Select(options=['All polls', 'Adults', 'Voters'], name='Subgroup')
select = pn.widgets.Select(name='Select', options=['All polls', 'Adults', 'Voters'])


# # Create the slider for the date range
# date_range_slider = pn.widgets.DateRangeSlider(name='Date Range')
# date_range_slider = pn.widgets.DateRangeSlider(
#     name='Date Range Slider',
#     start=dt.datetime(2017, 1, 1), end=dt.datetime(2019, 1, 1),
#     value=(dt.datetime(2017, 1, 1), dt.datetime(2018, 1, 10)),
#     step=2
# )


# # Create the slider for the moving average window
# moving_av_slider = pn.widgets.IntSlider(name='Moving Average Window', start=1, end=10, value=3)

# create_plot(subgroup_widget, date_range_slider, moving_av_slider)

# Bind the widgets to the create_plot function
final = pn.bind(create_plot,select)
template.main.append(final)



# # Combine everything in a Panel Column to create an app
# app = pn.Column(subgroup_widget, date_range_slider, moving_av_slider, update_plot)

# # set the app to be servable
# app.servable()