请看一下页面:
https://docs.bokeh.org/en/latest/docs/reference/models/widgets.tables.html#bokeh.models.widgets.tables.HTMLTemplateFormatter https://docs.bokeh.org/en/latest/docs/reference/models/widgets.tables.html#bokeh.models.widgets.tables.HTMLTemplateFormatter
我一直在尝试将该格式化程序用于我的数据表,但遇到问题:表文件的位置附加在实际链接之前。
如何使用格式化程序创建正确重定向到目标页面的 url 链接?
EDIT:
这是我正在使用的代码:(这是来自 python 的 bokeh 包):
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))
This create the following table:
您可以在检查窗格中看到该链接是正确的。
但是,当点击它时,它会重定向到页面: