Reputation: 21
I have connected my github repo to Heroku and am using that to deploy a file called main.py from my main branch. The code in main.py is as follows
# In[29]:
# In[30]:
import pandas as pd
import numpy as np
import panel as pn
import holoviews as hv
import holoviews.plotting.bokeh
from bokeh.models import HoverTool
from holoviews.selection import link_selections
from holoviews import dim, opts
#from holoviews.operation.datashader import datashade, rasterize, shade, dynspread, spread
#import holoviews.operation.datashader as hd
# In[31]:
#Post stats
views_df = pd.read_csv("data/wh1_public_views_imps_8345346.csv")
comments_df = pd.read_csv("data/qrc_8345346_responses.csv")
# In[32]:
#Profile / User stats
profiles_df = pd.read_csv("data/rallypoint_production_profiles_7-19-23.csv")
users_df = pd.read_csv("data/rallypoint_production_users_7-19-23.csv")
# In[36]:
users_df["easting"], users_df["northing"] = hv.Tiles.lon_lat_to_easting_northing(
users_df["longitude"], users_df["latitude"]
)
# In[37]:
#Concat the users and profiles df on user id column
users_profiles_df = users_df.merge(profiles_df, on='user_id', how='left')
# In[38]:
#Filter users_profiles_df to just logged in users who have viewed the post, and then drop duplicate viewers
filtered_users_profiles_df = users_profiles_df.merge(views_df, on='profile_id', how='inner')
filtered_users_profiles_df.drop_duplicates(subset='profile_id', inplace=True, ignore_index=True)
# In[39]:
filtered_users_profiles_df['birth_year'] = filtered_users_profiles_df.birth_year.replace(0, np.nan)
filtered_users_profiles_df.drop(columns=['gender.1', 'marital_status.1'], inplace=True)
# In[40]:
#Dataframe for commenter engagement
comments_filtered_df = users_profiles_df.merge(comments_df, on='profile_id', how='inner')
comments_filtered_df.drop_duplicates(subset='profile_id', inplace=True, ignore_index=True)
# In[41]:
filtered_users_profiles_df['created_at'] = pd.to_datetime(filtered_users_profiles_df.created_at)
filtered_users_profiles_df['created_at_year'] = filtered_users_profiles_df['created_at'].dt.year
# In[42]:
hv.extension('bokeh')
ls = link_selections.instance()
plot_research_dataset = hv.Dataset(filtered_users_profiles_df)
open_street_map = hv.Tiles('https://tile.openstreetmap.org/{Z}/{X}/{Y}.png', name="OSM").opts(width=600, height=550)
points = hv.Points(plot_research_dataset, ['easting', 'northing'], ['birth_year'])
tooltips = [
('birth_year', '@birth_year')]
hover = HoverTool(tooltips=tooltips)
data_points = points.opts(opts.Points(tools=[hover], size=5))
#table = hv.Table(plot_research_dataset, ['INSTNM_cleaned', 'keywords'])
branch_histogram = hv.operation.histogram(plot_research_dataset, dimension='branch_id', normed=False)
profile_created_at_histogram = hv.operation.histogram(plot_research_dataset, dimension='created_at_year', normed=False)
#data_map = rasterize(points, x_sampling=1, y_sampling=1, cmap=cc.fire, width=900, height=480).opts(tools=[hover], fontsize=5)
overlay = open_street_map * data_points
show_plot = ls(overlay) + ls(branch_histogram) + ls(profile_created_at_histogram)
#show_plot
pn.panel(show_plot).servable(title='Updated Holovews App')
When I run this same file locally in a virtual environment using 'bokeh serve --show main.py', everything renders as it should at http://localhost:5006/main. But when serving through Heroku I only get a blank white page. The repo is connecting properly as I get the "Updated Holoviews App" text when hovering over the browser tab. Since there are no errors in the Heroku application log, I'm guessing this is an issue with my Holoviews/Bokeh statements to serve the plot rather than a Heroku issue. The Heroku application log is as follows:
"2023-08-03T18:17:31.485568+00:00 app[web.1]: 2023-08-03T18:17:31.485568+00:00 app[web.1]: sys.exit(main()) 2023-08-03T18:17:31.487031+00:00 app[web.1]: 2023-08-03 18:17:31,486 Starting Bokeh server version 3.2.1 (running on Tornado 6.3.2) 2023-08-03T18:17:32.764914+00:00 app[web.1]: 2023-08-03 18:17:32,764 User authentication hooks NOT provided (default user enabled) 2023-08-03T18:17:32.770631+00:00 app[web.1]: 2023-08-03 18:17:32,770 Bokeh app running at: http://0.0.0.0:55173/main 2023-08-03T18:17:32.770704+00:00 app[web.1]: 2023-08-03 18:17:32,770 Starting Bokeh server with process id: 2 2023-08-03T18:17:33.086521+00:00 heroku[web.1]: State changed from starting to up 2023-08-03T18:17:41.000000+00:00 app[api]: Build succeeded 2023-08-03T18:18:48.344006+00:00 heroku[router]: at=info method=GET path="/" host=rp-bokeh-test-baf37200c9e5.herokuapp.com request_id=44007d18-bf9a-494a-8104-e45e89a8b080 fwd="98.115.41.108" dyno=web.1 connect=0ms service=1ms status=302 bytes=183 protocol=https 2023-08-03T18:18:56.350991+00:00 heroku[router]: at=info method=GET path="/main" host=rp-bokeh-test-baf37200c9e5.herokuapp.com request_id=c137514f-ad1d-42ff-b18b-bf319a69d3ec fwd="98.115.41.108" dyno=web.1 connect=0ms service=7959ms status=200 bytes=5086 protocol=https "
Any guidance would be much appreciated!
Cheers,
Joe
EDIT: The 'data' folder in the code above contains files stored in GitHub LFS. I'm aware that LFS and Heroku don't play nicely together in their native state. I'm using the GitHub LFS buildpack found here . It's not throwing any errors so I don't think that is the problem, but I could very well be wrong.
Upvotes: 2
Views: 162
Reputation: 475
I have faced similar issue while running a flask application, later seemed I was missing a driver code to invoke the main function on Heroku and some missing configs.
try changing your file content as follows on the last line instead of directly calling the panel method:
if __name__ == '__main__':
pn.panel(show_plot).servable(title='Updated Holovews App')
also verify your proc file configs too pointing to the method you are using to invoke your application.
a sample procfile with gunicorn may look like:
web: gunicorn your_main_file_name.__main__:main_method
In your case you may construct somewhat similar to this:
web: gunicorn main.__main__:pn
Also do not forget to add gunicorn to the requirements file :) if you have not added. Good luck with the solution.
Upvotes: 0