Unable to load Plotly graphs from Jupyter notebook to Github - github

I have imported following packages in code in my Jupyter notebook and have plotted few graphs. However, when I am uploading python file on github the graphs are not showing.
I have also tried using nbviewer as suggested in some of the posts but even in nbviewer the plotly graphs are appearing blank.
Libraries imported:
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import plotly.io as pio
from IPython.display import Image
nbviewer URL:
https://nbviewer.org/github/rj180492/Python/blob/main/Covid-19%20Impacts%20Analysis%20using%20Python.ipynb

Try:
pip install plotly
...as your first cell in the notebook and then try NBviewer. It worked for me. I was pretty sure it was working when it took several minutes for NBviewer to load the first time.
My NBviewer Example
I guess the other libraries are part of Nbviewer by default.
Curiously, my first version just had one plotly plot and it worked. Single color points though. When I got fancy and added another plot that had multiple colors, neither plot rendered. It also took hours to update. After pushing the version with pip install, NBviewer updated right away, it just took a long time to load.

Those having a related issue should note that the OP wrote in the comments below that despite it working for me via nbviewer when I ran the same notebook and posted my results on GitHub, OP had issues still. What sorted it out in that case so the plots showed up in nbviewer (yet still not in the GitHub quick-preview, which is as expected currently) was going to settings in the repository and choosing 'Pages' > 'Source' and from that dropdown selecting branch as main.
nbviewer is meant to the way to share things with other from the Jupyter ecosystem. (There are some others closely related, such as notebook{sharing}space
that is similar yet private by default because you don't need to have it on GitHub and the URLs are generated in a way others won't see unless you share publicly because of complex.) The nice thing about nbviewer is that is is meant for non-tech savvy.
Plotly should render on nbviewer and in many cases is still interactive, such as here where you can click and rotate or zoom the plots, as nbviewer will allow javascript whereas GitHub presently doesn't.
I put in comments that I wasn't seeing what you are and have linked to demonstrations.
Always only think of the GitHub page as a quick preview. See more about this here, here, here, plus there's other present deficiencies I have noted but haven't pointed to other places (text justification with Pandas dataframes, etc.). Static GitHub-notebook viewing in the browser is also not inviting for those unfamiliar with GitHub as it is embedded in an interface meant to get GitHub users to the code & not to feature the notebook content. Nbviewer does a better job featuring the content.

The method that worked for me was the following:
install these libraries:
pip install plotly cufflinks char_studio
then add these lines:
import cufflinks as cf
import chart_studio.plotly as py
import plotly.express as px
import plotly.graph_objects as go
import plotly.figure_factory as ff
import plotly.io as pio
from plotly.offline import init_notebook_mode
then
pio.renderers.default = "notebook_connected"
init_notebook_mode(connected=False)
cf.go_offline()
To be honest, I don't know why that worked, but you can see this as an example

Related

How do I get transformers' .from_pretrained("model") to consistently show download progress in a Jupyter Notebook?

I'm running a Jupyter Lab instance on a remote server which I access through my browser
I'm working with a notebook from a venv kernel that imports the AutoTokenizer and AutoModelForCausalLM classes from transformers, then downloads the elements for each from a model we'll call "model", using each class' .from_pretrained method.
the actual importing and downloading works fine; however, the first time I ran the cells containing AutoTokenizer.from_pretrained("model") and AutoModelForCausalLM.from_pretrained("model"), a text-based download progress bar appeared in the output text. this went through each file download until the kernel crashed (for reasons that I am yet to troubleshoot, but I suspect are related to storage allocations).
when I ran the code again, everything worked the same, but the progress bars never reappeared. the same thing happened a few weeks ago when I tried this the first time with a different model and slightly different environment
What I've tried:
I've tried creating a new kernel from a new venv. I've tried restarting jupyter. neither made a difference
there was a warning that appeared underneath the transformers import that suggested I should install ipywidgets. this was there the first time when the progress bar did appear, and again when it didn't, but somewhere online suggested that ipywidgets and progress bars could be linked, so I imported it to the venv anyway. this unsurprisingly did not help
I've tested whether I get output at all: I do. if I enter 1+1, "2" outputs. I also still got the ipywidgets a warning a few times before I installed it
I made sure that the output is not just being collapsed. View -> Menu -> Collapse/Expand all Outputs does not make anything new appear, besides some ellipses.
I tried doing pip install --upgrade jupyter_client, but it basically said there's nothing further to upgrade.
I tried a browser based on a different engine (chromium instead of ff). I tried with my adblocker on and off
if I download a different model, that does seem to work, once, but then as soon as the kernel crashes a single time trying to download that model, it will never show them again, even when it's clearly actually downloading them

Gitattributes ignored by github

I have uploaded some projects on my GitHub using the web interface. The project is code written in a py file and a rapport + code written in ipynb. This has led to Jupiter notebook becoming my top languages. I don’t want that.
I have tried to add a reposetoryname.gitattributes file and this line of code in the file
Prosjekt_Teknisk_fysikk.ipynb linguist-detectable=false
I expected this to show python as the only language used in the repo. This however did not happen, and the ratio is unchanged. I know github uses caching and it takes a while for the change to show. I have waited more than 10 hours, so I don’t think It has to do with that. I have also tried to delete and reupload using the web browser.
Edit also tried
Prosjekt_Biofysikk.ipynb -linguist-vendored
nothing happened

PyPlot figure not shown in VS Code Jupyter "UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure."

I run Julia inside Jupyter notebook within the Microsoft Visual Studio Code IDE.
When I try to make a PyPlot plot, the figure is not shown at and instead I am seeing the following message:
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
The figure will be shown when a PyPlot.display_figs() line will be added at the end of the cell code (note that the display_figs method is not exported so it needs be prepended with PyPlot).
Note that I observe this happening from time to time on some VS Code installation so I publish here this workaround so other people can easily google it.

What is the best way to turn IPython Notebooks on Github to a blog?

I've some IPython notebooks which I maintain at GitHub. I would like to turn them into a blog. I would like to have a discussion area at the end of the notebooks so that readers can comment. I do not want users to be able to execute the codes directly on the site (it is enough if they can see the notebooks), if they want to execute, they can copy the codes and run on their own computers. If possible I do not want a separate copy of the notebooks, I would like to have a single copy for ease of maintenance. What is the best way (preferably a free way) to achieve this?
Thanks
Hamel Husain recently posted to the Jupyter discourse forum a very full-featured Jupyter blogging system hosted on GitHub Pages called fastpages. It seems well documented and state-of-the-art. It allows a comments section, see here.
It seems you want to export a static version of the notebooks? You can use a tool like nbconvert which according to its documentation:
allows you to convert a Jupyter .ipynb notebook document file into another static format including HTML, LaTeX, PDF, Markdown, reStructuredText, and more. nbconvert can also add productivity to your workflow when used to execute notebooks programmatically.
You can export in your desired format and add the remaining markup for commenting or other functionality.

Matlab - import data tool

i have got a problem with the import data tool in matlab.
I just installed matlab this morning, at first it worked. However after shutting down the computer once, it doesn't work anymore.
More specifically, it opens and load data from .txt or spreadsheet, but when i click to import data to my workspace, instead of showing the progress in the waitbar it shows an error message:
IMPORT TOOL - couldn't find waitbar handles
any suggestion?
Sounds like the import tool works as intended until it cannot find the wait bar. A waitbar is a loading progress bar, which is available every basic installation of MATLAB (no toolbox required). Either the waitbar is created (do you see it?), but somehow not passed correctly through a broken connection between the import tool and the waitbar, or the waitbar function wasn't installed correctly.
I conclude your installation wasn't finished properly, so: uninstall MATLAB and reinstall it in one go (without pausing the installation).
You could also provide the system details you're installing on and the MATLAB version. Maybe someone knows of a certain condition of your particular setup that might cause the problem.