散景HTML模板格式化程序不起作用 [英] Bokeh HTML template formatter not working
问题描述
请查看页面:
我一直在尝试将该格式化程序用于我的数据表,但遇到了一个问题:表文件的位置被附加在实际链接之前.
I have been trying to use that formatter for a datatable of mine, but am having a problem : the location of the table file is appended before the actual link.
如何使用正确重定向到目标页面的格式化程序创建url链接?
How create a url link with the formatter that correctly redirect to the target page?
这是我正在使用的代码:(这是python的bokeh软件包):
Here is the code I am using: (this is the bokeh package from python):
from bokeh.io import output_file, show
from bokeh.layouts import widgetbox
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, DateFormatter, TableColumn, HTMLTemplateFormatter
from datetime import datetime
from pandas import Timestamp
start, end = datetime(2018,4,18), datetime(2018,4,18,23,59)
input = {
'datetime': [Timestamp('2018-04-18 00:34:16')],
'event': ['Barbara Bush, former US First Lady, 1925-2018'],
'url': ['https://www.ft.com/content/336e7f52-4189-11e8-93cf-67ac3a6482fd']}
output_file("data_table.html")
source = ColumnDataSource(input)
columns = [
TableColumn(
field="datetime",
title="Datetime",
width = 50,
formatter = DateFormatter(format = '%Y-%m-%d %H:%M')),
TableColumn(
field='event',
title='Event',
width = 150,
formatter = HTMLTemplateFormatter(template = '<a href="<%= url %>"><%= value %></a>'))]
data_table = DataTable(source=source, columns=columns, width=1000, height=1000)
show(widgetbox(data_table))
这将创建下表:
您可以在检查窗格中看到链接正确.
You can see in the inspect pane that the link is correct.
但是,当单击它时,它会重定向到页面:
However, when clicking on it, it redirect to the page:
推荐答案
这是因为href值不是有效的URL,因此将其视为相对于您的域的路径.添加另一个斜杠:
It's because the href value isn't a valid URL, so it's treated as a path relative to your domain. Add another slash:
https://www.google.com/search
代替
https:/www.google.com/search
在第二个示例中,href属性周围的双引号"字符是双引号的风格更强的版本,并且不是有效的HTML.改用它:
In the second example, the "double-quote" characters around the href attribute are the more stylized versions of double quotes, and aren't valid HTML. Use this instead:
HTMLTemplateFormatter(template = '<a href="<%= url %>"><%= value %></a>'))]
这篇关于散景HTML模板格式化程序不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!