Jupyter: embed live interactive widgets - python-3.x

According to the Jupyter blog here, it is now possible to embed interactive widgets in a static webpage:
Live interactive widgets can now be embedded into static web pages or blogs by inserting an html snippet containing the serialized widget state. This also works with custom widget libraries. See http://jupyter.org/embed-jupyter-widgets.html.
When I open the example above, in firefox or chrome, I get the interactive widgets alright!
However, if I create a new notebook with the same bit of python code, save the notebook as html, and then copy-paste the embeddable HTML snippet to render the interactive widgets, it is not working. At best I obtain an image of the widget state, but nothing interactive.
Has anyone managed to replicate the HTML page with interactive widgets? Is there something that I am missing?

We made Kyso for exactly this. You can embed a jupyter notebook into a website using kyso.io, and as long as the widgets are supported by BokehJS dashboard, the notebook will be interactive. Here is an example
PS. (disclaimer - I’m a founder of kyso)

It's been a long time since the question was asked but I will answer with today technology.
In order to embed interactive widgets you need a backend but there is a Project called MyBinder that can be used as a backend in the cloud for free. This was used as the foundation of a library called NBinteract, which can convert any notebook with interactive widgets in a single HTML webpage.
These HTMLs load a script from a cdn and manage all the interaction with MyBinder by their own.
There are some examples in their website and I also published a post in my blog where I used this technology along with Dockerfile, ffmpeg, matplotlib, animations and interactive widgets. So I believe this approach is quite robust and flexible.
The official docs says you need a repo but I could manage to use gists instead and submited an issue in the main repo explaining how to do it.

Related

How do I dynamically set Chrome Extension Icon based on an image from a different URL

Currently I am migrating my MV2 chrome extension into MV3.
With my MV2 extension, I can dynamically set my extension's icon using an image from a remote url using a code similar to the answer of this stackoverflow topic : Chrome Extension: Icon from URL
With the introduction of manifest-v3 and service workers, the service worker lost access to the DOM, making calls to creating instances of Image and canvas impossible.
My MV3-extension is now using nodeJS. I was looking into a combination of JSDOM, node-canvas, and OffScreenCanvas to implement the original code but no success as of yet.
What would be the best approach to set the icon dynamically (chrome.actions.setIcon), based on an image remotely hosted?
Thank you very much.
This was answered by wOxxOm in the comments for anybody looking into this same issue.
createImageBitmap + OffScreenCanvas can be successfully used in a service worker, no need for JSDOM or any external libraries.

Switching Google Docs from Canvas to DOM mode - programmatically?

My question is regarding this update (https://workspaceupdates.googleblog.com/2021/05/Google-Docs-Canvas-Based-Rendering-Update.html) from May 2021 that affects our chrome extension, that we are just finding out about now.
We have a Chrome Extension that we wrote in 2020 that needs to manipulate the DOM to highlight passages of text in google docs documents. This has obviously stopped working because Google Docs have switched from DOM to Canvas.
We did some digging around and looks like this extension here - WriQ - (https://chrome.google.com/webstore/detail/wriq/kfkohpkagbjoncihbogfnjnddimfbgea), when installed and activated, seems to force the document to switch from Canvas to DOM mode. I could be wrong, but that's the impression I get when I do this:
When I don't have WriQ installed and activated, $(".kix-paragraphrenderer") in the console of a Google Docs document page returns null - meaning the Google Doc renderer is using the new default Canvas mode.
When I have WriQ installed and activated, (and refresh the Google Docs page if already open) $(".kix-paragraphrenderer") in the console of a Google Docs document page returns an element - meaning the Google Doc renderer is switching to DOM mode.
Can anyone explain this? Is there a way to programatically trigger the DOM mode? That's what WriQ seems to be doing.
You can try setting window._docs_force_html_by_ext = <extension-id>. That will force Google Docs to render the HTML DOM instead of Canvas.
Google is whitelisting some applications which can use a script forcing the document to a HTML Fallback version which reminds of the time before canvas or as an Annotated Canvas which makes it possible to make extension integrations with the SVG canvas.
You need to apply for whitelisting to access these features:
https://docs.google.com/forms/d/e/1FAIpQLScFxMgvXlq2KMsp0UIM66pvThTF1hpojiXQTqyq9txW79OWag/viewform

Embed images in Vala project for later use in UI

Context
I'm new to Vala development (although I have some years of experience with C#) under Linux, and I decided to recreate one of my C# programs, however, I need to use images in the UI.
My problem
How can I embed resource files (such as images) for later use in the UI? How to access them later? And how to put them in a button?
What I'm using
I'm using Linux (Mint) and Anjuta development IDE, with the Glade UI designer integrated. The Vala project targets a GTK+ 3.0 project.
What I've tried
I have tried adding a new specific objective for images, adding them into the project... But I don't seem to succeed.
I have seen the default images provided by Linux, and those work just fine, but I need to add my own.
Thanks in advance!
The normal approach would be to install your images to PREFIX/share/pixmaps/YOUR_APP. For example Gnumeric installs some .png files in /usr/share/pixmaps/gnumeric/.
You can use GResource to embed binary files (like images) into your executable if you really want to. The glib-compile-resources command can be added to your build system (see also this question).
You can also use icons from the users icon theme.
You didn't write what component you want to use to display your images, so I'll assume Gtk.Image here.
Gtk.Image has several constructors for the purpose of loading the image:
from_icon_name loads the image from the current icon theme (which is useful to support user themes).
from_resource loads the image from an embedded GResource.
from_file loads the image from a file.
See the main documentation of Gtk.Image for more methods. Some other widgets have similar methods to load images (for example toolbar buttons).
You should not use from_stock any more (There was a stock system in Gtk+ that is being replaced by freedesktop.org icon schemas).

Retrieve Google results without using the Custom Search API

Recently I've been working on an idea that requires me to query Google Images and retrieve links for images matching that search term. My most promising candidate for a usable Google Images API was the Google Web Search API, but it looks like it's going to be going out of service as of tomorrow:
https://developers.google.com/web-search/docs/
The API that replaced it is the Google Custom Search API, but it's a little discouraging to use:
Google API Custom Search with Python - Programmatic Search Results
100 search results a day is a very strict limit; that's just four searches per hour. I also don't want to have to go through the hassle of creating some custom search bar that I'm never going to use except through Python
I decided to turn to parsing HTML directly from the results page. This presents a problem, though, because nowhere inside the page's HTML is there any direct link to the image, only referrer URLs. This is true of the javascript-enabled and javascript-disabled versions of Google Images (so even if Python spoofs javascript as enabled, nothing). I'm not sure where to go from here. Could anyone refer me to some obscure, updated library that I've somehow overlooked, or give me some pointers?
You could use Selenium Webdriver to actually execute the JavaScript and click on the images in the thumbnail view. Once an image has been opened, the link is in the DOM and you can scrape it from there. All Webdriver does is open an actual browser and simulate a user. You can even run it as a headless browser if you use xvfbwrapper. The downside is that even then, you will need all the dependencies of the browser you are using installed on your server.
However, scraping Google is against their terms of service and they will make an effort of blocking you as quickly as possible. So, unless you pass through the captchas (which are linked to sessions), you will possibly not be able to make a whole lot of searches before being blocked this way, either.

How should I go about rendering a webpage without using a browser?

Basically I am currently doing some research, and I am interested to find out how I could render web pages without a browser: I have some algorithms that I would like to run to calculate the visual aspect of each blocks of DOM node(s) for each page.
What you're asking for basically, is a browser rendering engine, otherwise known as a layout engine... For example, Firefox uses the Gecko layout engine to render the pages. Theoretically, you could adopt this engine for whatever project you're working on, saving you a lot of time.
The Gecko engine is used in more projects than just Firefox, and since it's open source, you could easily get the source code and try to throw it in an application.
Wikipedia has a nice list of layout engines, so there are other alternatives to Gecko, like GtkHTML.
Basically, you want to create the data structures a browser internally creates so that it knows how to render the page.
Check out the Firefox source.
I suspect it's rather complex.

Resources