@@ -1007,3 +1007,54 @@ def toggle(n):
1007
1007
dash_dcc .wait_for_contains_text (".gtitle" , gravity )
1008
1008
dash_dcc .wait_for_no_elements (".gtitle-math" )
1009
1009
assert dash_dcc .driver .execute_script ("return !!window.MathJax" )
1010
+
1011
+
1012
+ @pytest .mark .parametrize ("is_eager" , [True , False ])
1013
+ def test_grva014_load_mathjax (dash_dcc , is_eager ):
1014
+ app = Dash (__name__ , eager_loading = is_eager )
1015
+
1016
+ gravity = "$F=\\ frac{Gm_1m_2}{r^2}$"
1017
+
1018
+ app .layout = html .Div (
1019
+ [
1020
+ html .Button ("Add Second MathJax" , id = "btn" ),
1021
+ dcc .Graph (
1022
+ mathjax = False ,
1023
+ id = "gd" ,
1024
+ figure = {
1025
+ "data" : [{"y" : [3 , 1 , 2 ]}],
1026
+ "layout" : {"title" : {"text" : gravity }},
1027
+ },
1028
+ ),
1029
+ html .Div ("initial" , id = "out" ),
1030
+ ]
1031
+ )
1032
+
1033
+ @app .callback (
1034
+ Output ("out" , "children" ), Input ("btn" , "n_clicks" ), prevent_initial_call = True
1035
+ )
1036
+ def add_math (n ):
1037
+ return dcc .Graph (
1038
+ mathjax = True ,
1039
+ id = "gd2" ,
1040
+ figure = {
1041
+ "data" : [{"y" : [3 , 1 , 2 ]}],
1042
+ "layout" : {"title" : {"text" : gravity }},
1043
+ },
1044
+ )
1045
+
1046
+ dash_dcc .start_server (app )
1047
+
1048
+ # Initial state: no MathJax loaded or rendered, unformatted text is shown
1049
+ dash_dcc .wait_for_contains_text ("#gd .gtitle" , gravity )
1050
+ dash_dcc .wait_for_no_elements ("#gd .gtitle-math" )
1051
+ assert not dash_dcc .driver .execute_script ("return !!window.MathJax" )
1052
+
1053
+ btn = dash_dcc .find_element ("#btn" )
1054
+ btn .click ()
1055
+
1056
+ # One click: MathJax is loaded and rendered on the second, unformatted text is gone
1057
+
1058
+ dash_dcc .wait_for_element ("#gd2 .gtitle-math" )
1059
+ assert gravity not in dash_dcc ._get_element ("#gd2 .gtitle" ).text
1060
+ assert dash_dcc .driver .execute_script ("return !!window.MathJax" )
0 commit comments