gpt4 book ai didi

javascript - Bokeh HTML 模板格式化程序不起作用

转载 作者:行者123 更新时间:2023-12-01 09:29:31 24 4
gpt4 key购买 nike

请查看页面:

https://docs.bokeh.org/en/latest/docs/reference/models/widgets.tables.html#bokeh.models.widgets.tables.HTMLTemplateFormatter

我一直在尝试将该格式化程序用于我的数据表,但遇到问题:表文件的位置附加在实际链接之前。

如何使用格式化程序创建正确重定向到目标页面的 url 链接?

<小时/>

编辑:

这是我正在使用的代码:(这是来自 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))

这将创建下表: enter image description here

您可以在检查 Pane 中看到该链接是正确的。

但是,当点击它时,它会重定向到页面:

enter image description here

最佳答案

这是因为 href 值不是有效的 URL,因此它被视为相对于您的域的路径。添加另一个斜杠:

https://www.google.com/search

而不是

https:/www.google.com/search

在第二个示例中,href 属性周围的“双引号”字符是双引号的更加风格化的版本,并且不是有效的 HTML。改用这个:

HTMLTemplateFormatter(template = '<a href="<%= url %>"><%= value %></a>'))]

关于javascript - Bokeh HTML 模板格式化程序不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50086517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com