Comments (3)
This is relatively simple to achieve by extending the Panel ReactiveHTML class with the latest version of Panel. The trickier part is that Panel now uses a Shadow DOM, so needs some JS to work, something like this should work:
from panel.reactive import ReactiveHTML
import param
class PanelHighchart(ReactiveHTML):
chart_js: dict = param.String()
_template: str = """<div id="phighchart"></div>"""
_scripts: dict = {}
__javascript__ = ["https://code.highcharts.com/highcharts.js", "https://code.highcharts.com/modules/exporting.js"]
prefix: str = "document.addEventListener('DOCContentLoaded', function() {"
suffix: str = "});"
def __init__(self, **params):
super().__init__(**params)
self._scripts = self._generate_highchart(self.chart_js)
def _generate_highchart(self, chart_js: str):
# remove the prefix and suffix
chart_js_literal: str = chart_js[len(PanelHighchart.prefix):len(chart_js)-len(PanelHighchart.suffix)]
# and replace null with the phighcharts div, which we can reference in the scripts as if the variable already exists
chart_js_literal = chart_js_literal.replace("null,", "phighchart,")
init: str = """console.log("Initing...");
if (phighchart !== null) {
""" + chart_js_literal + """
} else {
console.log("Not found...");
}"""
render: str = f"""console.log("Rendering...");
self.init();"""
scripts: dict = {
"init": init,
"render": render
}
return scripts
and then call with pnl_chart: PanelHighchart = PanelHighchart(chart_js=chart.to_js_literal())
.
If we could optionally drop the JS event listener wrapper, that would solve having to remove it manually. The rest is just setting the HTML element to the element reference itself for highcharts to render to (and some debugging comments that can be removed!).
from highcharts-core.
Wow, @IanG-21 ! Thanks! This is super helpful, looks great, and I'll be taking a closer look at it shortly as I look at the integration with Panel. In the meantime, if you'd like to clean-up and file a PR, that would be awesome - but if not, then no worries: I'll be experimenting with this a bit in preparation for hopefully the next minor release.
from highcharts-core.
Just by way of FYI, PR #131 has added a flag to remove the event listener prefix. While it hasn't been released yet, that PR has been merged into the release branch for the next Highcharts for Core minor version (v.1.6, in branch rc-v.1.6
).
from highcharts-core.
Related Issues (20)
- Simplify .from_pandas()
- Simplify .from_csv()
- Add SeriesBase.convert_to() method to convert between series types.
- Add CallbackFunction.from_python() method
- python highcharts integration issue with loading script in Jupyter Notebook HOT 8
- BUG - Custom point attributes are lost in from_dict call HOT 2
- Boxplot rendering in jupyterlab - highcharts-more issue? HOT 8
- `from_pandas` method raises `HighchartsValueError` when a DataFrame column is a datetime object HOT 2
- FEATURE REQUEST: JS Literal Sanitising HOT 2
- Request new feature: Rendering Highchart core in Streamlit HOT 1
- Unable to use chart.marginRight HOT 12
- Add Highcharts Core for Python support for Highcharts v.11.2
- Blank charts after 1.4.0 update when PieSeries is included HOT 7
- Add support for `_repr_html_` to Highcharts Core for Python
- Add support for `_repr_png_`, `_repr_svg_`, `_repr_jpeg_` to Highcharts Core for Python
- Add support for `_ipython_display_` to Highcharts Core for Python HOT 1
- Add GPT 4.5 Turbo support
- BUG : chart.display() rendering in Jupyter Lab but not in Jupyter notebook (in web browser)
- BUG Cannot set chart_options of Exporting class to HighchartsOptions instance
- Format of data for large number of points to be a list instead of dict HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from highcharts-core.