2

Please have a look at the page:

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

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.

How create a url link with the formatter that correctly redirect to the target page?


EDIT:

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))

This create the following table: enter image description here

You can see in the inspect pane that the link is correct.

However, when clicking on it, it redirect to the page:

enter image description here

1
  • Can you post some code? Commented Apr 29, 2018 at 12:29

1 Answer 1

1

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

Instead of

https:/www.google.com/search

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>'))]
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for pointing that out - it's a bit unfortunate that the link in the bokeh page was wrong, as even with a correct link the error appears - I posetd a more detailled sdescription of my problem in the question section
@jimbasquiat updated to answer the second part of your question.
Open Source is a team effort. Little typos like that are especially unlikely to be found by core devs busy with other issues. The best recourse is to file an issue, or much better, make the tiny PR to fix it directly.
@bigreddot Don't mind doing it, but i'm quite noob... What is a PR? How to do it?
@jimbasquiat It's a "Pull Request" which is the mechanism that changes get merged into a project. There's quite a few tutorials online about how to make your first PR, but maybe the simplest thing for now is just to file an issue about it so it does not get lost: github.com/bokeh/bokeh/issues Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.