I'm trying to show the following code results on webEngineView.setHtml:
from ahp_calculator import ahp_calculator
AC = ahp_calculator()
AC.open_calculator()
So it will be displayed in the right box (instead of folium map) after clicking a button on the left as shown in the figure below:
I found ways to display maps, Tables and Plotes using SetHtml. But how to render and display ahp_calculator?
Related
I would like to make a simple app to explore a set of PNG files. In general, there will be several selection widgets (e.g. for sex and handedness), and a PNG file to display for each combination of selections.
I am trying to do this using HoloMap with a dictionary of holoviews.Div objects, so that the interactivity does not depend on having a live Python server.
The individual cells of the HoloMap display correctly, but the interactive HoloMap does not display the image components of the Div objects.
To demonstrate, I make a HoloMap to explore two PNG files, A or B.
import holoviews as hv
hv.extension("bokeh") # To render in Notebook environment.
# Define format template for html div to display a figure.
# See https://holoviews.org/reference/elements/bokeh/Div.html.
div_format = """
<figure>
<img src=" {pic} " height='200' width='200'>
<figcaption> {caption} </figcaption>
"""
# Map to URLs of two images.
pic_dict = {"A": "https://assets.holoviews.org/logo/holoviews_color_icon_500x500.png",
"B": "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png"}
# Map to holoviews div objects for the images.
div_map = {key: hv.Div(div_format.format(pic=pic,
caption="Figure "+key)) \
for key, pic in pic_dict.items()}
holomap = hv.HoloMap(div_map, kdims="Figure")
holomap["A"]
# Shows PNG A and caption "Figure A".
Alternatively, we can also display holomap["B"].
The holomap as a whole lets us interactively explore the figure captions (with a selection widget it generates). However, the images themselves are not displayed in the interactive HoloMap--is this a bug? If so, is there a work-around? Or a better way to explore a set of images?
holomap
# Shows interactive display with figure caption and select widget, but no PNG.
Instead of using HoloMap, an interactive image explorer could potentially be built directly from bokeh widgets, with a little javascript to change the image to reflect user selection.
This solution uses bokeh and javascript directly instead of relying on holoviews to do that under the hood.
For example, to explore two PNG files by selecting 'A' or 'B':
from bokeh.models import CustomJS, Div, Select
from bokeh.layouts import column
from bokeh.io import output_notebook, show
# Map to URLs of two images.
pic_dict = {"A": "https://assets.holoviews.org/logo/holoviews_color_icon_500x500.png",
"B": "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png"}
option_keys = list(pic_dict.keys())
option_values = list(pic_dict.values())
# Make widget to display html, set to show first URL.
bk_html = Div(text='<img src="' + option_values[0] + '"/>')
# Make widget to select key from pic_dict.
bk_select = Select(options=option_keys, value=option_keys[0], title="Image selection")
# Link select-widget value to html-widget text, to show selected image.
bk_select.js_on_change(
'value',
CustomJS(
args={"html": bk_html},
code=f"""
console.log('Entering bk_select jscallback.');
// Array of URLs corresponding to this.options.
const option_lookup = {option_values};
// Look up URL corresponding to chosen option.
var option_index = this.options.indexOf(this.value);
var url = option_lookup[option_index];
// Set HTML text to display image at URL.
html.text = '<img src="' + url + '"/>';
console.log('Set image to ', html.text);
"""
)
)
# Lay out widgets in a column.
layout = column(bk_select, bk_html)
# To display Bokeh output inline in a Jupyter notebook:
output_notebook(hide_banner=True)
# Display the layout.
show(layout)
I am creating a Folium map with markers and popups. At the moment they are just static strings, however when I load the map the popup window only shows about 2 words before it moves to a new line. How do I get it to automatically resize so that it will appear on 1 line? The training course I am taking does not have this issue, but the instructor is using Folium 0.3.
Here is the code I am using. I am running Python 3.9.7 using VS Code.
import folium
map = folium.Map(location=[38.58, -99.09], zoom_start=6, tiles = "Stamen Terrain")
map.add_child(folium.Marker(location= [38.2,-99.1], popup="Hi this is a marker", icon=folium.Icon(color='green')))
map.save("Map1.html")
You can put the text of the popup inside a folium.Popup() object and specify the max_width parameter to 100%.
Extract from the Folium documentation :
max_width (int for pixels or text for percentages, default '100%') – The maximal width of the popup.
You can modify your code that way :
map.add_child(
folium.Marker(
location= [38.2,-99.1],
popup=folium.Popup("Hi this is a marker", max_width="100"),
icon=folium.Icon(color='green')
)
)
I am generating histograms using go.Histogram as described here. I am getting what is expected:
What I want to do is to show some statistics of the selected data, as shown in the next image (the white box I added manually in Paint):
I have tried this and within the function selection_fn I placed the add_annotation described here. However, it does nothing. No errors too.
How can I do this?
Edit: I am using this code taken from this link
import plotly.graph_objects as go
import numpy as np
x = np.random.randn(500)
fig = go.Figure(data=[go.Histogram(x=x)])
fig.show()
with obviously another data set.
I want to create world maps using folium within a text editor (geany), not using notebooks. this piece of code will work but i cant see the output. i.e, the actual map. How do i get it to display the map.
import pandas as pd
import numpy as np
import folium
m = folium.Map(location=[40.0150, -105.2705])
# Display the map
m
You can use import webbrowser and open the saved html file in your browser.
import folium
import webbrowser
m = folium.Map(location=[40.0150, -105.2705])
m.save("map.html")
# Display the map
webbrowser.open("map.html")
Just like yabberth said save the map as map.html after saving html call the system command like os.system('map.html')
I need to display the title of an image when it is opening in a new window using Image.show(). But the title displaying is some random text.
Discovered the solution of the problem using cv2. But I need a solution in PIL.
img = Image.open("picture.jpg")
Image._showxv(img, title='Result')
I expect the output to display the title of the image when it is showing. But getting some random text now.