- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含 Bokeh 图的完整 html 文件。现在我正在尝试使用 python 电子邮件模块发送该 html。我只是使用此处给出的第三个示例:https://docs.python.org/2.7/library/email-examples.html (如何创建 HTML 消息......)
但这似乎只是向我发送了一封空白电子邮件。
我还尝试了其他一些包含嵌入式 javascript 的 html。这似乎很好(禁用 JS,我不关心)。
关于可能发生的事情以及我可以改变什么的任何线索?
这是 html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bokeh Scatter Plots</title>
<link rel="stylesheet" href="http://cdn.bokeh.org/bokeh/release/bokeh-0.9.0.min.css" type="text/css" />
<script type="text/javascript" src="http://cdn.bokeh.org/bokeh/release/bokeh-0.9.0.min.js"></script>
<script type="text/javascript">
Bokeh.$(function() {
var all_models = [{"attributes": {"line_color": {"value": "white"}, "fill_color": {"value": "#5ab738"}, "tags": [], "doc": null, "fill_alpha": {"value": 0.7}, "height": {"units": "data", "field": "z"}, "width": {"units": "data", "field": "width_cat"}, "y": {"field": "midz"}, "x": {"field": "catz"}, "id": "20b3f29b-629c-4d0d-a8ef-9bc05e5b178a"}, "type": "Rect", "id": "20b3f29b-629c-4d0d-a8ef-9bc05e5b178a"}, {"attributes": {"nonselection_glyph": null, "data_source": {"type": "ColumnDataSource", "id": "23913a89-b55a-4191-a5c3-3195acc7e1f4"}, "tags": [], "doc": null, "selection_glyph": null, "id": "5eda121f-edca-48cf-aed6-1e109b54b2ff", "glyph": {"type": "Rect", "id": "20b3f29b-629c-4d0d-a8ef-9bc05e5b178a"}}, "type": "GlyphRenderer", "id": "5eda121f-edca-48cf-aed6-1e109b54b2ff"}, {"attributes": {"geometries": [], "tags": [], "doc": null, "id": "c43afbcc-a846-4f33-a482-039a0fd206e8"}, "type": "ToolEvents", "id": "c43afbcc-a846-4f33-a482-039a0fd206e8"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "tags": [], "doc": null, "major_label_orientation": 0.7853981633974483, "axis_label": "categories", "formatter": {"type": "CategoricalTickFormatter", "id": "f27df891-c727-4511-af15-049332957dda"}, "ticker": {"type": "CategoricalTicker", "id": "9d14f049-833c-4895-bb18-a13fd30163a3"}, "id": "50005101-7498-4430-8b3e-fece52250277"}, "type": "CategoricalAxis", "id": "50005101-7498-4430-8b3e-fece52250277"}, {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b", "attributes": {"x_range": {"type": "FactorRange", "id": "46a7ffcd-19f4-4d8a-ae50-e01aa946b82e"}, "right": [], "above": [], "tags": [], "tools": [{"type": "PanTool", "id": "d6948ffa-b6f5-4379-a967-82dca90488a0"}, {"type": "WheelZoomTool", "id": "03df0ff2-3de4-4341-aecc-1bc593ebb8f2"}, {"type": "BoxZoomTool", "id": "3b6ab084-b09a-4131-809e-282113f78357"}, {"type": "PreviewSaveTool", "id": "8264e0e1-e9b3-44cd-aed7-02d01251240a"}, {"type": "ResizeTool", "id": "d3c48641-01cb-467c-91ee-3a0c6085d201"}, {"type": "ResetTool", "id": "3f0c4f54-5e2b-4253-b7e4-9bb9a7deabab"}, {"type": "HelpTool", "id": "3a1fb46c-8124-4374-83a4-2dd5bf4f6860"}], "title": "Bar example p", "renderers": [{"type": "CategoricalAxis", "id": "50005101-7498-4430-8b3e-fece52250277"}, {"type": "LinearAxis", "id": "42be7469-495b-4e8a-8021-a9a3191cecf0"}, {"type": "Grid", "id": "42bb2980-8afe-426d-9894-767dd3e4caad"}, {"type": "GlyphRenderer", "id": "8eb8810b-0e44-4851-89df-79debf7dbe2a"}, {"type": "GlyphRenderer", "id": "5eda121f-edca-48cf-aed6-1e109b54b2ff"}], "plot_width": 400, "extra_y_ranges": {}, "extra_x_ranges": {}, "tool_events": {"type": "ToolEvents", "id": "c43afbcc-a846-4f33-a482-039a0fd206e8"}, "plot_height": 400, "doc": null, "id": "36f2771e-837b-4b64-b541-523ef126784b", "y_range": {"type": "Range1d", "id": "90174572-530c-4de3-8906-e80952108b06"}, "below": [{"type": "CategoricalAxis", "id": "50005101-7498-4430-8b3e-fece52250277"}], "left": [{"type": "LinearAxis", "id": "42be7469-495b-4e8a-8021-a9a3191cecf0"}]}}, {"attributes": {"doc": null, "id": "9d14f049-833c-4895-bb18-a13fd30163a3", "tags": []}, "type": "CategoricalTicker", "id": "9d14f049-833c-4895-bb18-a13fd30163a3"}, {"attributes": {"doc": null, "id": "f27df891-c727-4511-af15-049332957dda", "tags": []}, "type": "CategoricalTickFormatter", "id": "f27df891-c727-4511-af15-049332957dda"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "tags": [], "doc": null, "axis_label": "values", "formatter": {"type": "BasicTickFormatter", "id": "a5efb989-af95-4129-983a-b867fe96eddf"}, "ticker": {"type": "BasicTicker", "id": "57a0ff59-725c-4d01-920a-2a3f8c65e6c4"}, "id": "42be7469-495b-4e8a-8021-a9a3191cecf0"}, "type": "LinearAxis", "id": "42be7469-495b-4e8a-8021-a9a3191cecf0"}, {"attributes": {"tags": [], "doc": null, "mantissas": [2, 5, 10], "id": "57a0ff59-725c-4d01-920a-2a3f8c65e6c4"}, "type": "BasicTicker", "id": "57a0ff59-725c-4d01-920a-2a3f8c65e6c4"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "tags": [], "doc": null, "dimension": 1, "ticker": {"type": "BasicTicker", "id": "57a0ff59-725c-4d01-920a-2a3f8c65e6c4"}, "id": "42bb2980-8afe-426d-9894-767dd3e4caad"}, "type": "Grid", "id": "42bb2980-8afe-426d-9894-767dd3e4caad"}, {"attributes": {"doc": null, "id": "a5efb989-af95-4129-983a-b867fe96eddf", "tags": []}, "type": "BasicTickFormatter", "id": "a5efb989-af95-4129-983a-b867fe96eddf"}, {"attributes": {"column_names": ["width_cat", "stackedz", "stackedy", "cat", "width", "zero", "midz", "midy", "y", "caty", "catz", "z"], "tags": [], "doc": null, "selected": {"2d": {"indices": []}, "1d": {"indices": []}, "0d": {"indices": [], "flag": false}}, "callback": null, "data": {"width_cat": [0.2, 0.2, 0.2, 0.2, 0.2], "stackedz": [6.5, 9.5, 8.0, 6.0, 6.0], "stackedy": [3.0, 3.5, 1.0, 2.0, 2.5], "cat": ["C1", "C2", "C3", "D1", "D2"], "width": [0.8, 0.8, 0.8, 0.8, 0.8], "zero": [7.0, 12.0, 14.0, 8.0, 7.0], "midz": [0.5, 2.5, 6.0, 2.0, 1.0], "midy": [3.0, 3.5, 1.0, 2.0, 2.5], "y": [6, 7, 2, 4, 5], "caty": ["C1:0.333333333333", "C2:0.333333333333", "C3:0.333333333333", "D1:0.333333333333", "D2:0.333333333333"], "catz": ["C1:0.666666666667", "C2:0.666666666667", "C3:0.666666666667", "D1:0.666666666667", "D2:0.666666666667"], "z": [1, 5, 12, 4, 2]}, "id": "23913a89-b55a-4191-a5c3-3195acc7e1f4"}, "type": "ColumnDataSource", "id": "23913a89-b55a-4191-a5c3-3195acc7e1f4"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "dimensions": ["width", "height"], "tags": [], "doc": null, "id": "d6948ffa-b6f5-4379-a967-82dca90488a0"}, "type": "PanTool", "id": "d6948ffa-b6f5-4379-a967-82dca90488a0"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "dimensions": ["width", "height"], "tags": [], "doc": null, "id": "03df0ff2-3de4-4341-aecc-1bc593ebb8f2"}, "type": "WheelZoomTool", "id": "03df0ff2-3de4-4341-aecc-1bc593ebb8f2"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "dimensions": ["width", "height"], "tags": [], "doc": null, "id": "3b6ab084-b09a-4131-809e-282113f78357"}, "type": "BoxZoomTool", "id": "3b6ab084-b09a-4131-809e-282113f78357"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "tags": [], "doc": null, "id": "8264e0e1-e9b3-44cd-aed7-02d01251240a"}, "type": "PreviewSaveTool", "id": "8264e0e1-e9b3-44cd-aed7-02d01251240a"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "tags": [], "doc": null, "id": "d3c48641-01cb-467c-91ee-3a0c6085d201"}, "type": "ResizeTool", "id": "d3c48641-01cb-467c-91ee-3a0c6085d201"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "tags": [], "doc": null, "id": "3f0c4f54-5e2b-4253-b7e4-9bb9a7deabab"}, "type": "ResetTool", "id": "3f0c4f54-5e2b-4253-b7e4-9bb9a7deabab"}, {"attributes": {"plot": {"subtype": "Chart", "type": "Plot", "id": "36f2771e-837b-4b64-b541-523ef126784b"}, "tags": [], "doc": null, "id": "3a1fb46c-8124-4374-83a4-2dd5bf4f6860"}, "type": "HelpTool", "id": "3a1fb46c-8124-4374-83a4-2dd5bf4f6860"}, {"attributes": {"callback": null, "factors": ["C1", "C2", "C3", "D1", "D2"], "doc": null, "tags": [], "id": "46a7ffcd-19f4-4d8a-ae50-e01aa946b82e"}, "type": "FactorRange", "id": "46a7ffcd-19f4-4d8a-ae50-e01aa946b82e"}, {"attributes": {"end": 13.200000000000001, "callback": null, "doc": null, "tags": [], "start": 0, "id": "90174572-530c-4de3-8906-e80952108b06"}, "type": "Range1d", "id": "90174572-530c-4de3-8906-e80952108b06"}, {"attributes": {"line_color": {"value": "white"}, "fill_color": {"value": "#f22c40"}, "tags": [], "doc": null, "fill_alpha": {"value": 0.7}, "height": {"units": "data", "field": "y"}, "width": {"units": "data", "field": "width_cat"}, "y": {"field": "midy"}, "x": {"field": "caty"}, "id": "43271b33-7e9c-4120-a177-4d0f1c233de1"}, "type": "Rect", "id": "43271b33-7e9c-4120-a177-4d0f1c233de1"}, {"attributes": {"nonselection_glyph": null, "data_source": {"type": "ColumnDataSource", "id": "23913a89-b55a-4191-a5c3-3195acc7e1f4"}, "tags": [], "doc": null, "selection_glyph": null, "id": "8eb8810b-0e44-4851-89df-79debf7dbe2a", "glyph": {"type": "Rect", "id": "43271b33-7e9c-4120-a177-4d0f1c233de1"}}, "type": "GlyphRenderer", "id": "8eb8810b-0e44-4851-89df-79debf7dbe2a"}];
Bokeh.load_models(all_models);
var plots = [{'modeltype': 'Plot', 'elementid': '#806c01c5-0a0d-4d12-9df9-5de64399e878', 'modelid': '36f2771e-837b-4b64-b541-523ef126784b'}];
for (idx in plots) {
var plot = plots[idx];
var model = Bokeh.Collections(plot.modeltype).get(plot.modelid);
Bokeh.logger.info('Realizing plot:')
Bokeh.logger.info(' - modeltype: ' + plot.modeltype);
Bokeh.logger.info(' - modelid: ' + plot.modelid);
Bokeh.logger.info(' - elementid: ' + plot.elementid);
var view = new model.default_view({
model: model,
el: plot.elementid
});
Bokeh.index[plot.modelid] = view;
}
});
</script>
</head>
<body>
<div class="plotdiv" id="806c01c5-0a0d-4d12-9df9-5de64399e878"></div> </body>
</html>
这是 python 脚本:
#!/usr/bin/env python
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
me = 'abc@mac.com'
you = 'abc@abc.com'
# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Link JavaScript big"
msg['From'] = me
msg['To'] = you
# Create the body of the message (a plain-text and an HTML version).
#text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttps://www.python.org"
# example below
'''
html = """\
<!DOCTYPE html>
<html>
<body>
<h1>My First JavaScript</h1>
<button type="button"
onclick="document.getElementById('demo').innerHTML = Date()">
Click me to display Date and Time.</button>
<p id="demo"></p>
</body>
</html>
"""
'''
# html goes here
html = """\
"""
# Record the MIME types of both parts - text/plain and text/html.
#part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
#msg.attach(part1)
msg.attach(part2)
# Send the message via local SMTP server.
s = smtplib.SMTP('localhost')
# sendmail function takes 3 arguments: sender's address, recipient's address
# and message to send - here it is sent as one string.
s.sendmail(me, you, msg.as_string())
s.quit()
bokeh html 包含在注释“# html goes here”下方的三重引号中(就像上面的示例一样)
最佳答案
如评论中所述,电子邮件不呈现 HTML。
我想到了三个选项:将绘图转换为图像并发送,将绘图放到服务器并将指向绘图的链接放入电子邮件或将 HTML 作为附件发送。我认为您可能无法单独在 HTML 主体上按原样显示情节。
将情节作为附件的一种简单方法是通过 Red Mail 进行:
from redmail import EmailSender
email = EmailSender(
host="smtp.myserver.com", port=587,
username="me@example.com", password="<PASSWORD>"
)
plot_content = "<!DOCTYPE html><html lang="en">....</html>"
msg = email.send(
sender=["me@example.com"],
receivers=["you@example.com"],
subject="Link JavaScript big",
text="The plot is attached.",
attachments={'plot.html': plot_content},
)
如果您喜欢这种方式,它还支持将图像嵌入到 HTML 正文中。它还是高度可定制的并且功能非常丰富,因此很可能足以满足您的用例。
Red Mail 的文档:https://red-mail.readthedocs.io
免责声明:我是作者,请按您认为合适的方式使用它。
关于javascript - 使用 python 电子邮件或其他模块在电子邮件中发送 Bokeh 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31555116/
我用 bokeh.plotting.Figure.line 画了下面的图。我如何添加垂直引用线来强调 Feb/14 的一个点? 这是另一个情节。这是 bokeh.charts.Bar。我想添加水平指南
我使用 python 在 Bokeh 中创建了一个散点图。我想创建一个小部件,允许用户更改散点图中点的颜色。有没有简单的方法可以做到这一点?我找到了一个基于 JQuery 的颜色选择器小部件 ( ht
我有一个 bokeh 应用程序,我可以在其中读取各种文件(6 到 12 个)并生成 DataTable 来比较几个不同的变量。 所以我有一个生成 DataTable 的循环,将它们添加到列表中,然后最
典型的 Bokeh 散点图可能如下所示: 其中 x 和 y 限制均为 [0,1]。如何删除轴上 0 之前并延伸到 1 之外的额外空间?这样最终图的左角为坐标 (0,0),左上角和右下角分别为 (0,1
我正在尝试创建一个 Bokeh 图,它允许我通过单击复选框来切换图中线条的可见性。 我开始尝试对复选框组使用 js 回调,但不幸的是,实际上并没有为复选框组实现 js 回调。 任何人都可以提出另一种方
例如,我有 button = Button(label="0", type="success") 选择此按钮后,我想将标签更改为“1”,反之亦然。有没有简单的方法来实现这一目标? 编辑: RadioB
我团队中的一些人,包括我自己,发现在 Bokeh 散点图中使用 circle 非常令人迷惑。方法,对于图中数据的初始自动缩放拟合,我们可以为我们的数据拨入合理的大小,例如使用 plot.circle(
所以我想做的是一个带有线条和圆圈的简单图形 http://docs.bokeh.org/en/latest/docs/quickstart.html#getting-started 但带有在鼠标悬停在
考虑一个垂直堆积条形图,其中每一列都由多个条形(段)组成。是否可以在每个段上添加工具提示?目前,相同的工具提示附加到组成该列的所有段。 from bokeh.core.properties impor
In[21]: from bokeh.charts import Bar, output_file, show In[22]: dict = {'sec': {u'A': 10, u'B': 20}}
在 Bokeh 中实现树形图需要什么?类似于这个 DS 示例的东西会很好—— http://bl.ocks.org/robschmuecker/7880033 我只是想可视化一个数据结构,所以只需要平
我了解如何指定在 Bokeh 中显示的特定刻度,但我的问题是是否有一种方法可以分配特定的标签来显示与位置。例如 plot.xaxis[0].ticker=FixedTicker(ticks=[0,1]
有什么方法可以为图例添加标题,例如左侧为当前图例,右侧为带有标题的图例。这个特殊的图例被放置在情节之外,所以我不知道是否可以用文本字形来伪造它。 最佳答案 从最新版本的 Bokeh (1.2) 开始,
问题:我的 python 应用程序启动了一个 Bokeh 服务器,如本文所述: http://matthewrocklin.com/blog/work/2017/06/28/simple-bokeh-
我正在使用 Bokeh 图制作折线图,我想标记实际的点(用线穿过它们),而不是仅仅标记线本身。我怎样才能做到这一点?我浏览了文档和用户指南,但似乎找不到答案。谢谢! 最佳答案 假设您正在使用 boke
我将一个 Bokeh Figure 实例作为输入传递给另一个函数,我需要在那里修改它的源代码。 不知道该怎么做! 这就是我创建图形实例的方式: source = ColumnDataSource({'
据我所知,我可以通过设置 responsive=True 来使 Bokeh 图响应 div 的宽度。然而,我感兴趣的是让 Bokeh 图只在一定程度上做出响应。有没有一种方法可以让我设置 Bokeh
我有一个 Bokeh 服务器应用程序。我想在命令行上传递自定义选项: bokeh serve /path/to/script.py --my-option foo 这可能吗? Bokeh 会以某种方式
我有一个图,它使用来自一些原始数据的值(在 0-20 的 x/y 范围内),以及一些导致一些相当大的 x/y 值(例如 -1000 到 1000+)的最小化数据。因此,我所做的绘图需要我手动单击缩放以
在Web应用程序中,我想让用户使用bokeh的漂亮的框/套索选择工具来选择绘制图像中的感兴趣区域。我想接收选定的像素,以便在python中进行进一步的操作。 对于散点图,这类似于gallery,很容易
我是一名优秀的程序员,十分优秀!