Agenda
Goals
Refactoring
Introduction to refactoring non-reactive code
Moving code into a python module
Learn some Shiny best practices:
shiny
modules Agenda
Goals
Refactoring
Introduction to refactoring non-reactive code
Moving code into a python module
From wikipedia:
In computer programming and software design, code refactoring is the process of restructuring existing source code - changing the factoring - without changing its external behavior.
For example:
shiny
modulesWhen should you refactor?
Avoid premature refactoring
shiny
modulesAgenda
Goals
Refactoring
Introduction to refactoring non-reactive code
Moving code into a python module
Most Shiny app code is non-reactive
Note
It’s fine to include this code inside reactive functions.
But as your app grows you should separate them.
Reactive context makes them inherently harder to:
Non-reactive functions are familiar and predictable, since you can:
In turn, this makes your reactive code much clearer
Agenda
Goals
Refactoring
Introduction to refactoring non-reactive code
Moving code into a python module
A python module could be as simple as a single python file.
You can import functions from this file into your shiny app.
Benefits:
Namespacing
Testing
Separation of functionality
Potential to re-use across multiple applications
In a file example.py
In your app:
Note
Keep your reactive code in the shiny app
Move non-reactive code into python modules