Skip to content

Aladin and Nicegui: how to run Javascript code automatically? #4086

Answered by falkoschindler
jovenitti asked this question in Q&A
Discussion options

You must be logged in to vote

The issue is likely because the Aladin initialization script runs before the DOM element is fully loaded and available. When you reload the page, it works because all resources are cached and the timing happens to work out.

Here's how to fix it by ensuring the script runs after the DOM is ready:

ui.html('<div id="aladin" style="width:800px;height:600px"></div>')
ui.add_body_html("""
    <script src="https://aladin.cds.unistra.fr/AladinLite/api/v3/latest/aladin.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            A.init.then(() => A.aladin('#aladin'));
        });
    </script>
""")

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jovenitti
Comment options

Answer selected by jovenitti
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants