Hi, I was wondering if someone could give me a hand with my problem.
I have developed an app with bokeh and it works perfectly when I use the command ‘bokeh server–show my_app.py’.
I am trying to put this app on google sites in order to create an App that people can use. The problem, is that the easiest way seems to be to use the code in ‘html’ something that I had before introducing buttons, select and something else that modifies functions of my app in real time.
I understand that there might be a way to pass all my code written in python to html so I can upload it to google sites but I can’t find it.
As far as I know Google sites only hosts static HTML content, which means you will not be able to run a Bokeh server application there. There is ongoing work to take advantage of the cutting-edge “pyiodide” work for compiling Python into WASM but that is very early days, and nothing is released. You have two options:
Create standalone HTML output with Bokeh, that only uses JS callbacks (no Python on_change)
Host your Bokeh server app on some server somewhere that supports running python apps
Regarding creating a standalone HTML was something I thought about but in my code right now I have both JS callbacks and Python on_change defined. In that sense, would it be possible to pass all interactions defined as Python on_change to JS callbacks? My understanding was that there was some limitation and that some interactions could only happen through Python on_change.
Regarding hosting my bokeh server app on another server where a python app can run, do you know of any that would be recommended? Looking at the Bokeh Apps I find on the official website I am totally impressed by how clean and good they look, they are awesome.
You would have to translate all your Python code into JavaScript code. That might be fairly easy, or it might be impossibly difficult. It depends entirely on what the Python code does, and what third-party libraries it calls out to. E.g. if your Python callbacks just do basic things then translating may be simple and straightforward. If your Python callbacks use OpenCV or TensorFlow then translating is difficult or impossible, because those things don’t exist in the browser.
Regarding hosting my bokeh server app on another server where a python app can run, do you know of any that would be recommended?
There are lot of options, I don’t really have anything specific to recommend. It depends entirely on your budget, any existing infrasructure or cloud services you might already use, etc.
Looking at the Bokeh Apps I find on the official website I am totally impressed by how clean and good they look, they are awesome.
Thanks for the kind words. For reference, those were created and deployed using AWS Elastic Beanstalk.
Heroku has (or at least had) a “free” tier and a hobby tier @ $7/month when last I checked.
I went with the hobby tier for my initial development bc it enabled me to use add-ons with databases, in-memory data stores, etc. useful to interact with user data in my particular applications.
If you decide to go that route, you can search this forum for setting up the server, and of course ask questions if you run into any issues.
Holoviz panel, which leverages the bokeh server also has info on their website about how to set up the configuration files to run a server on Heroku.
If you want to use bokeh only without the panel layer, you would replace the panel serve ... syntax in the Heroku ProcFile with bokeh serve ....
There is also a requirements.txt file that Heroku uses to define which python packages and such are required to build your app. In that file, you would replace panel with bokeh for an app where you wanted to use only bokeh without the panel layer.
In principle I think I will try to pass it JS callbacks as it is a good exercise and google sites offers me enough flexibility, so I will give it a try.
I have some doubts about that part of the code, for that I have simplified the functions and I have some doubts for which I have thought to raise them in the forum so that all the members can see them, and if they have a solution, they could be of help to other people.
To continue with the good functioning of this forum, I have thought of opening new questions with another title to facilitate the access to other people.
As a test I tried to configure the Heroku page and I’m having some problems in the final part ‘git push heroku main’ but through some forum I hope I can solve it.
Sorry for your troubles with the Heroku deployment. Details on the specific nature of problems encountered will help others provide directed feedback.
If you login to the Heroku dashboard, do you see any logs/messages about what failed? This can help narrow down to problems building the application, launching the application, etc.
One of the most common reasons for a failure is that a required dependency is not included in the requirements.txt manifest of packages that your app uses. Without further details it is difficult to ascertain the problem in your setup.
For what it is worth, I did not use the “git push” method for updating builds on Heroku. I maintain a git repository for my development code, but when I want to specifically target it to Heroku, I used command line tools to do so.
I did my development on Mac OS X for these projects. In that environment, I used brew to install the heroku command line interface (CLI). The syntax was something like the following
Then I have my ‘draft_html_short.ipynb’ file and a file called ‘requirements.txt’ where I have the libraries I define in the ‘draft_html_short.ipynb’ file.
Then I follow the instructions I see in Heroku and enter the following in my terminal:
$ heroku create draftapp05032022
$ heroku login
$ heroku git:remote -a draftapp05032022
$ git push heroku master
With this last step I get the following:
Enumerating objects: 22, done.
Counting objects: 100% (22/22), done.
Delta compression using up to 8 threads
Compressing objects: 100% (12/12), done.
Writing objects: 100% (22/22), 7.44 KiB | 7.44 MiB/s, done.
Total 22 (delta 6), reused 20 (delta 6), pack-reused 0
remote: error: pathspec ‘.’ did not match any file(s) known to git.
remote:
remote: ! Heroku Git error, please try again shortly.
remote: ! See http://status.heroku.com for current Heroku platform status.
remote: ! If the problem persists, please open a ticket
remote: ! on https://help.heroku.com/tickets/new
remote: ! and provide the Request ID 460bd4af-3d98-4bbf-94f3-ac1e28b2d156
remote:
To https://git.heroku.com/test-app05032022.git
! [remote rejected] master → master (pre-receive hook declined)
error: failed to push some refs to ‘https://git.heroku.com/test-app05032022.git’
It doesn’t work either by changing ‘main’ to ‘master’, actually when I set:
the truth is that it is a bit strange because now I have been able to run to the end the example that we are discussing but the web page appears blank but I do not see any error.
Following this example, I should be able to publish my apps because in principle, unless you tell me otherwise, it would be the same process using any ‘python’ file (or jupyter notebook).
Heroku works fine although I don’t know if it would allow me to load ‘data.csv’ from the same repository, although I would still need to know what’s going on with the example that I’m not able to see.
Regarding the blank webpage, a possible cause is that the websocket origin does not match what is allowed as prescribed in your Procfile.
If you log in to the Heroku dashboard for your app, you should be able to see the application logs and it will tell you if that is the error (or if something else is causing the page to not render).
Data uploading mechanisms is a large topic in and of itself and is probably better started as a separate thread. It really comes down to what your specific requirements are - loading user provided data or canned data stored with your app, how big are the files, are there security considerations for the data, etc?
The page still comes up blank when I try it in Google Chrome but I don’t see any errors (I’m talking about the example we were discussing). I enter the app from my Heroku page and I don’t see anything strange, although something must be wrong because if I search for the page directly from Safari the app doesn’t appear.
The data I’m referring to will be a fixed dataframe with several variables and a lot of rows but it could be loaded as a .CSV from the beginning and I wouldn’t need to load it anymore.
If you log in to your Heroku dashboard, click on the app of interest (in case you have more than one), it should take you to a new view that includes all the top-level info for that application.
Along the righthand side, there should be a column labeled Latest Activity. This shows updates related to builds succeeding or failing, builds deploying, etc. Do you see anything there? If yes, does it all make sense and do you see that your application has been successfully built and deployed?
As a next step, there is a banner along the top of that same view for the selected app. At the far-right, there is a More widget, where you can see additional information. Select “View Logs”. This will pull up logs from the app server and show you any problems with it running, any connection attempts, and successful connections, etc.
Is that where you looked and reported “no errors”? Does the server not show any lines like the following, which I excerpted from my test case to deploy the iris example we’re discussing above. The connection messages on the server happen when a client uses their web browser to go to the site.
when I look at ‘view logs’ after having tried to enter the website and still seeing everything white, I don’t see anything similar to what you indicate. What I see are the following lines:
The logs are telling you there is a mismatch in the allowed connections per the comment in an earlier post.
This error in the logs specifically shows that you are trying to connect from iris-kmeans-2 but your Procfile seems to be set up to expect iris-kmeans. The URLs absolutely must match per bokeh’s requirements.