Include folium in bokeh tabs - python

I would like to add a folium map to a bokeh tab.
Is it possible?
When I try i have an error like: expected an instance of type LayoutDOM, got folium of type map.
Otherwise is there another way to do chart in python with map and include it in tab?
Thank you :)

Bokeh has its own set of objects to represent the built-in widgets that it can display. Only these Bokeh objects can go inside Bokeh layouts like tab panes. However, one of the available widgets is Div, which let you put an HTML div with arbitrary content inside a Bokeh layout e.g.
div = Div(text="whatever HTML code you want")
layout = column(plot, div)
So you could put the raw HTML for a map as the content for one of these Div objects.

Related

multi-select dropdown Bokeh

I know that there are a bunch of widgets available in Bokeh, here:
https://docs.bokeh.org/en/latest/docs/user_guide/interaction/widgets.html
How can I integrate Bokeh Dropdown Menu with MultiSelect (or extend the Dropdown) in order to have a Multi-Select Dropdown? Is there anything built-in?
My expected result is a dropdown which one can select/deselect multiple options.
You can write you own custom Bokeh model extension using TypeScript. See Extending Bokeh for more information. Scroll down for links to some nice examples. You will need to install nodejs on your system to be able to compile TypeScript.
If the widget height is your main consideration than you could think of replacing the MultiSelect with CheckboxButtonGroup.

Q: How can I create dynamically an iframe inside a web content using Python?

I am trying to create an iframe inside a web content (no matter where exactly need to be inserted). The only way that I need to do this, is just by making it dynamically and also by using Python3+ version. The iframe's information is not important either. Id, class name and more can be random or custom. It is not necessary to insert specific data. Also, I don't need an answer about the height and the width. I already have solved it.
What do I mean dynamically? I mean that if someone clicks on a button then I need to insert this iframe. If someone clicks on another button then I need to delete it, and so on.
Check my code below:
def function(given_from_user_url):
"""return the iframe result"""
from IPython.display import IFrame
return IFrame(url, width='50%', height=350)
This function is returning an instance of an iframe with width equals with the 50% of the page and a height of 350 pixels. Then the result of this function you can use it was you want in your rest project. Is this what you are looking for?
Sounds like HTML / Javascript challenge. Why do you think it is related to python?

How to add toolTip for objects in QTextBrowser?

I'm adding some paragraphs in QTextBrowser and want to add toolTip for them. I tried using hover but QTextBrower doesn't support hover I think.
I'm able to call a function on clicking though.
EDIT:seperate toolTip for each one.
I don't know how you're adding the paragraphs, but if you're using markup the solution is simple: just use the title attribute.
<p title="tootip">some block of text</p>
However, if the paragraphs are being added programmatically, you can use QTextCharFormat, which has a setToolTip method.
Did you try this?
b=QTextBrowser()
b.setToolTip('Simple text browser')
It works for TextFields

How to draw an html table using bokeh?

I am new to bokeh, I search for examples in the documentation but it appears to me there is not in built method for creating tables. I have some data that I want to show in tabular format. I was wondering what is the easiest way to do that using Bokeh?
The reason I want to draw tables using Bokeh is because I am trying to put a table and two bar charts in the same html report. I was hoping to use one library(Bokeh) to do all my drawing because otherwise I will have to generate table using html generator and then add the html for bar chart generated via Bokeh to that. Hope that explains.
There's no built-in support to create an HTML table as of Bokeh 0.9.1, however it is very simple to embed Bokeh plots and widgets inside your own custom HTML templates. For instance, the new spectrogram shows a very customized HTML document with Bokeh plots and widgets embedded:
https://www.youtube.com/watch?v=L6p7Cd3uDis
So, I would recommend taking this approach. The documentation for embedding is located here:
http://docs.bokeh.org/en/latest/docs/user_guide/embed.html

Visualize a clickable graph in an HTML page

I have defined a data structure using pygraph. I can display that data easily as PNG using graphviz.
I would like to display the data graphically, but making each node in the graph clickable. Each node must be linked to a different web page. How would I approach this?
What I would like is:
Assign an href for each node
Display all the graph as image
Make each node in the image clickable
Tooltips for hover event: whenever the cursor is positioned on top of an edge / node, a tooltip should be displayed
I believe graphviz can already output an image as a map for use in html.
Check this doc or this one for how to tell graphviz to output a coordinate map to use. It will even append the url you specify, and there even is a version that only uses rectangles for mapping links
Edit:
You can also check this document by LanyeThomas which outlines the basic steps:
Create a GraphViz dot file with the required linking information,
maybe with a script.
Run GraphViz once to generate an image of the
graph.
Run GraphViz again to generate an html image-map of the graph.
Create an index.html (or wiki page) with an IMG tag of the graph,
followed by the image-map's html.
Direct the image-map urls to a Wiki
page with each node's name - generate the Wiki pages automatically if
needed.
Optionally, link directly to the class hierarchy image
generated by DoxyGen. Have the Wiki page link to any additional
documentation, including DoxyGen docs, images, etc.
You can use pygraphviz and cmapx
import pygraphviz
my_graph = pygraphviz.AGraph(id="my_graph", name="my_graph")
my_graph.add_node("node",
label="my_node",
tooltip="tooltip text \r next line", # use \r for new line
URL="http://ya.ru/",
target="_blank")
my_graph.layout(prog='dot')
my_graph.draw(path="my_graph.map", format="cmapx")
my_graph.draw(path="my_graph.svg", format="svg")
then use content of my_graph.map in html
<IMG SRC="my_graph.svg" USEMAP="#my_graph" />
... [content of my_graph.map] ...
You could use click maps:
<img src="graph.png" width="400" height="300" usemap="#mygraphmap">
<map name="mygraphmap">
<area shape="circle" coords="100,100,30" href="f8a08.htm">
<area shape="circle" coords="200,100,30" href="1d0f.htm">
</map>
You'd obviously have to find out the coordinates somehow.
edit:
You can also use rect or polygon for the shape attribute.
I think you can also add a mouseover or title attribute to the area elements.
more edit:
Or you could make graphviz output svg which can be integrated in the html5 DOM. I mean that you might be able to handle the elements inside a graph as a DOM-object.
Most of the suggested solutions involve an Image map format, but that's tricky. Not only that, you won't be able to edit the clickable SVG file in e.g. Inkscape afterwards to customize your drawing.
The SVG files that graphviz generates already have clickable links if you provide URLs. If you're having trouble with them, then perhaps you need to use an <object> tag rather than an <img> tag:
<object width="100%" data="./example.gv.svg" type="image/svg+xml"></object>
See also Insert clickable SVG image into Sphinx documentation.
If you are looking for a graphviz alternative, may be you could use jsPlumb Library. See some samples here
Also checkout JavaScript InfoVis Toolkit

Categories