Implementing javascript eCharts into niceGUI #3974
-
QuestionHi, I am trying to use the following example in a dashboard I am creating: https://echarts.apache.org/examples/en/editor.html?c=map-usa-projection I have saved the javascript in js/echarts_choropleth.js and am trying to call it to the site via the following Python code: from nicegui import ui, app
# NiceGUI app setup
@ui.page('/')
def main_page():
# first, tell server how to serve my js files
app.add_static_files('/js' , 'directory')
# in page method, add js file to <head> of created page
ui.add_head_html (f'<script type="text/javascript" src="/js/echarts_choropleth.js"> </script>')
ui.run() I found a similar issue here: #1588 however am unable to copy the methodology as the browser comes up with an uncaught syntax error: Uncaught SyntaxError: import declarations may only appear at top level of a module however I am only importing at the top of the javascript file! Apologies since I am fairly new to using niceGUI - I know this must be possible but it's a problem I've been struggling to solve for a while! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @HarryRogers0, I'm struggling to run your example... Where did you find echarts_choropleth.js? By the way, |
Beta Was this translation helpful? Give feedback.
Solution was reached by first loading the json file in via
then running the following javascript to ensure the json file was loaded before registering the map (this stops JavaScript error "Cannot read properties of undefined (reading 'regions')").