Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5d632f6
Load plotly.js from plotly.py
T4rk1n Aug 2, 2023
72ac574
External plotly.js from cdn.plot.ly
T4rk1n Aug 2, 2023
57ae31b
New plotlyjs external_url
T4rk1n Aug 3, 2023
6f94f38
Fix test tooltip
T4rk1n Aug 3, 2023
9c6aebd
Fix test_scripts
T4rk1n Aug 10, 2023
e03eacb
Fix test old dcc
T4rk1n Aug 10, 2023
5374e93
Merge branch 'dev' into feat/pjs-from-ppy
T4rk1n Aug 10, 2023
4c2bcff
fix test_grva002
T4rk1n Aug 11, 2023
09f5171
Merge branch 'dev' into feat/pjs-from-ppy
T4rk1n Aug 11, 2023
79ee66f
Merge branch 'dev' into feat/pjs-from-ppy
T4rk1n Aug 14, 2023
d501d63
Merge branch 'dev' into feat/pjs-from-ppy
T4rk1n Aug 21, 2023
81d2c52
Fix plotly.js url on the window at initial mount.
T4rk1n Aug 21, 2023
91f6c2c
Delay get plotlyjs version
T4rk1n Aug 22, 2023
32cbddf
Update changelog.
T4rk1n Aug 22, 2023
b5ae1fc
Remove async-plotlyjs from js_dist.
T4rk1n Aug 22, 2023
5ec9eb8
Remove plotly.js from dcc node modules.
T4rk1n Aug 22, 2023
fa52955
Add hooks for layout "pre" and "post"
KoolADE85 Aug 22, 2023
445da3e
Merge branch 'dev' into feature/layout-hooks
KoolADE85 Aug 22, 2023
8331d26
Update CHANGELOG
KoolADE85 Aug 22, 2023
8a61bf5
Refactor test to modify only the renderer instead of the whole index_…
KoolADE85 Aug 22, 2023
f3f03cd
build
T4rk1n Aug 22, 2023
cc7fde3
Merge pull request #2610 from plotly/feat/pjs-from-ppy
T4rk1n Aug 22, 2023
a2c294f
Add ability to pass renderer hooks as a constructor argument
KoolADE85 Aug 23, 2023
4412ec5
Document new hooks constructor arg
KoolADE85 Aug 25, 2023
5e3688b
Address code review style feedback
KoolADE85 Aug 25, 2023
e698327
Merge branch 'dev' into feature/layout-hooks
alexcjohnson Aug 25, 2023
e22bc10
Update CHANGELOG.md
alexcjohnson Aug 25, 2023
6cbac0e
Merge pull request #2630 from plotly/feature/layout-hooks
KoolADE85 Aug 25, 2023
7f4346f
Version 2.13.0
T4rk1n Aug 28, 2023
68bf290
Merge pull request #2632 from plotly/version-2.13.0
T4rk1n Aug 28, 2023
30f4076
Merge branch 'dev' into master-2.13.0
T4rk1n Aug 28, 2023
c618b78
Build artifacts 2.13.0
T4rk1n Aug 28, 2023
f3324ce
build
T4rk1n Aug 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
All notable changes to `dash` will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

## [2.13.0] 2023-08-28
## Changed

- [#2610](https://github.com/plotly/dash/pull/2610) Load plotly.js bundle/version from plotly.py

## Added

- [#2630](https://github.com/plotly/dash/pull/2630) New layout hooks in the renderer


## [2.12.1] - 2023-08-16

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os as _os
import sys as _sys

import dash as _dash

from ._imports_ import * # noqa: F401, F403, E402
Expand Down Expand Up @@ -121,33 +122,6 @@
"namespace": "dash",
"dynamic": True,
},
{
"relative_package_path": "dcc/plotly.min.js",
"external_url": (
"https://unpkg.com/dash-core-components@{}"
"/dash_core_components/plotly.min.js"
).format(__version__),
"namespace": "dash",
"async": "eager",
},
{
"relative_package_path": "dcc/async-plotlyjs.js",
"external_url": (
"https://unpkg.com/dash-core-components@{}"
"/dash_core_components/async-plotlyjs.js"
).format(__version__),
"namespace": "dash",
"async": "lazy",
},
{
"relative_package_path": "dcc/async-plotlyjs.js.map",
"external_url": (
"https://unpkg.com/dash-core-components@{}"
"/dash_core_components/async-plotlyjs.js.map"
).format(__version__),
"namespace": "dash",
"dynamic": True,
},
]
)

Expand Down
15 changes: 2 additions & 13 deletions components/dash-core-components/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions components/dash-core-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dash-core-components",
"version": "2.11.1",
"version": "2.12.0",
"description": "Core component suite for Dash",
"repository": {
"type": "git",
Expand All @@ -23,7 +23,6 @@
"test": "run-s -c lint test:intg test:pyimport",
"test:intg": "pytest --nopercyfinalize --headless tests/integration ",
"test:pyimport": "python -m unittest tests/test_dash_import.py",
"prebuild:js": "cp node_modules/plotly.js-dist-min/plotly.min.js dash_core_components_base/plotly.min.js",
"build:js": "webpack --mode production",
"build:backends": "dash-generate-components ./src/components dash_core_components -p package-info.json && cp dash_core_components_base/** dash_core_components/ && dash-generate-components ./src/components dash_core_components -p package-info.json -k RangeSlider,Slider,Dropdown,RadioItems,Checklist,DatePickerSingle,DatePickerRange,Input,Link --r-prefix 'dcc' --r-suggests 'dash,dashHtmlComponents,jsonlite,plotly' --jl-prefix 'dcc' && black dash_core_components",
"build": "run-s prepublishOnly build:js build:backends",
Expand All @@ -49,7 +48,6 @@
"mathjax": "^3.2.2",
"moment": "^2.29.4",
"node-polyfill-webpack-plugin": "^2.0.1",
"plotly.js-dist-min": "2.25.2",
"prop-types": "^15.8.1",
"ramda": "^0.29.0",
"rc-slider": "^9.7.5",
Expand Down
29 changes: 24 additions & 5 deletions components/dash-core-components/src/utils/LazyLoader/plotly.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
export default () => Promise.resolve(window.Plotly ||
import(/* webpackChunkName: "plotlyjs" */ 'plotly.js-dist-min').then(({ default: Plotly }) => {
window.Plotly = Plotly;
return Plotly;
}));
export default () => {
return Promise.resolve(window.Plotly || new Promise((resolve, reject) => {
/* eslint-disable prefer-const */
let timeoutId;

const element = document.createElement('script');
element.src = window._dashPlotlyJSURL;
element.async = true;
element.onload = () => {
clearTimeout(timeoutId);
resolve();
};
element.onerror = (error) => {
clearTimeout(timeoutId);
reject(error);
};

timeoutId = setTimeout(() => {
element.src = '';
reject(new Error(`plotly.js did not load after 30 seconds`));
}, 3 * 10 * 1000);

document.querySelector('body').appendChild(element);
}));
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def show_relayout_data(data):

dash_dcc.start_server(app)

time.sleep(1)

# use this opportunity to test restyleData, since there are multiple
# traces on this graph
legendToggle = dash_dcc.find_element(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def update_tooltip_content(hoverData):
assert 175 < coords[0] < 185, "x0 is about 200 minus half a marker size"
assert 175 < coords[1] < 185, "y0 is about 200 minus half a marker size"

elem = dash_dcc.find_element("#graph .nsewdrag")

ActionChains(dash_dcc.driver).move_to_element_with_offset(
elem, 5, elem.size["height"] - 5
).perform()
Expand Down
4 changes: 2 additions & 2 deletions dash/_dash_renderer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

__version__ = "1.15.5"
__version__ = "1.16.0"

_available_react_versions = {"16.14.0", "18.2.0"}
_available_reactdom_versions = {"16.14.0", "18.2.0"}
Expand Down Expand Up @@ -64,7 +64,7 @@ def _set_react_version(v_react, v_reactdom=None):
{
"relative_package_path": "dash-renderer/build/dash_renderer.min.js",
"dev_package_path": "dash-renderer/build/dash_renderer.dev.js",
"external_url": "https://unpkg.com/dash-renderer@1.15.5"
"external_url": "https://unpkg.com/dash-renderer@1.16.0"
"/build/dash_renderer.min.js",
"namespace": "dash",
},
Expand Down
10 changes: 10 additions & 0 deletions dash/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import string
from html import escape
from functools import wraps
from typing import Union
from dash.types import RendererHooks

logger = logging.getLogger()

Expand Down Expand Up @@ -267,3 +269,11 @@ def coerce_to_list(obj):

def clean_property_name(name: str):
return name.split("@")[0]


def hooks_to_js_object(hooks: Union[RendererHooks, None]) -> str:
if hooks is None:
return ""
hook_str = ",".join(f"{key}: {val}" for key, val in hooks.items())

return f"{{{hook_str}}}"
26 changes: 24 additions & 2 deletions dash/dash-renderer/build/dash_renderer.dev.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dash/dash-renderer/build/dash_renderer.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dash/dash-renderer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dash/dash-renderer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dash-renderer",
"version": "1.15.5",
"version": "1.16.0",
"description": "render dash components in react",
"main": "build/dash_renderer.min.js",
"scripts": {
Expand Down
17 changes: 17 additions & 0 deletions dash/dash-renderer/src/APIController.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ const UnconnectedContainer = props => {
}
});

useEffect(() => {
if (config.serve_locally) {
window._dashPlotlyJSURL = `${config.requests_pathname_prefix}_dash-component-suites/plotly/package_data/plotly.min.js`;
} else {
window._dashPlotlyJSURL = config.plotlyjs_url;
}
}, []);

let content;
if (
layoutRequest.status &&
Expand Down Expand Up @@ -123,14 +131,21 @@ function storeEffect(props, events, setErrorLoading) {
dispatch,
error,
graphs,
hooks,
layout,
layoutRequest
} = props;

if (isEmpty(layoutRequest)) {
if (typeof hooks.layout_pre === 'function') {
hooks.layout_pre();
}
dispatch(apiThunk('_dash-layout', 'GET', 'layoutRequest'));
} else if (layoutRequest.status === STATUS.OK) {
if (isEmpty(layout)) {
if (typeof hooks.layout_post === 'function') {
hooks.layout_post(layoutRequest.content);
}
const finalLayout = applyPersistence(
layoutRequest.content,
dispatch
Expand Down Expand Up @@ -190,6 +205,7 @@ UnconnectedContainer.propTypes = {
dispatch: PropTypes.func,
dependenciesRequest: PropTypes.object,
graphs: PropTypes.object,
hooks: PropTypes.object,
layoutRequest: PropTypes.object,
layout: PropTypes.object,
loadingMap: PropTypes.any,
Expand All @@ -203,6 +219,7 @@ const Container = connect(
state => ({
appLifecycle: state.appLifecycle,
dependenciesRequest: state.dependenciesRequest,
hooks: state.hooks,
layoutRequest: state.layoutRequest,
layout: state.layout,
loadingMap: state.loadingMap,
Expand Down
2 changes: 2 additions & 0 deletions dash/dash-renderer/src/AppContainer.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class UnconnectedAppContainer extends React.Component {
constructor(props) {
super(props);
if (
props.hooks.layout_pre !== null ||
props.hooks.layout_post !== null ||
props.hooks.request_pre !== null ||
props.hooks.request_post !== null ||
props.hooks.callback_resolved !== null ||
Expand Down
4 changes: 4 additions & 0 deletions dash/dash-renderer/src/AppProvider.react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const AppProvider = ({hooks}: any) => {

AppProvider.propTypes = {
hooks: PropTypes.shape({
layout_pre: PropTypes.func,
layout_post: PropTypes.func,
request_pre: PropTypes.func,
request_post: PropTypes.func,
callback_resolved: PropTypes.func,
Expand All @@ -25,6 +27,8 @@ AppProvider.propTypes = {

AppProvider.defaultProps = {
hooks: {
layout_pre: null,
layout_post: null,
request_pre: null,
request_post: null,
callback_resolved: null,
Expand Down
2 changes: 2 additions & 0 deletions dash/dash-renderer/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type Config = {
'Content-Type': string;
};
};
serve_locally?: boolean;
plotlyjs_url?: string;
};

export default function getConfigFromDOM(): Config {
Expand Down
2 changes: 2 additions & 0 deletions dash/dash-renderer/src/reducers/hooks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const customHooks = (
state = {
layout_pre: null,
layout_post: null,
request_pre: null,
request_post: null,
callback_resolved: null,
Expand Down
Loading