Return the current Dash app instance. Useful in multi-page apps when Python files within the `pages/` folder need to reference the `app` object but importing it directly would cause a circular import error.
()
| 42 | |
| 43 | |
| 44 | def get_app(): |
| 45 | """ |
| 46 | Return the current Dash app instance. |
| 47 | |
| 48 | Useful in multi-page apps when Python files within the `pages/` folder |
| 49 | need to reference the `app` object but importing it directly would cause |
| 50 | a circular import error. |
| 51 | """ |
| 52 | try: |
| 53 | ctx_app = app_context.get() |
| 54 | if ctx_app is not None: |
| 55 | return ctx_app |
| 56 | except LookupError: |
| 57 | pass |
| 58 | |
| 59 | if APP is None: |
| 60 | raise AppNotFoundError( |
| 61 | dedent( |
| 62 | """ |
| 63 | App object is not yet defined. `app = dash.Dash()` needs to be run |
| 64 | before `dash.get_app()`. |
| 65 | |
| 66 | `dash.get_app()` is used to get around circular import issues when Python files |
| 67 | within the pages/` folder need to reference the `app` object. |
| 68 | """ |
| 69 | ) |
| 70 | ) |
| 71 | return APP |
searching dependent graphs…