0
# Core Functions
1
2
Essential functions for configuration, serving, binding, and converting objects to Panel components. These functions form the foundation of Panel applications and provide the basic functionality needed to get started.
3
4
## Capabilities
5
6
### Object Conversion
7
8
Automatically converts Python objects to appropriate Panel components.
9
10
```python { .api }
11
def panel(obj, **params):
12
"""
13
Convert Python objects to Panel components automatically.
14
15
Parameters:
16
- obj: Any Python object to convert
17
- **params: Additional parameters to pass to the component
18
19
Returns:
20
Appropriate Panel component (Pane, Widget, or Layout)
21
"""
22
```
23
24
### Application Serving
25
26
Serves Panel applications on a web server with various configuration options.
27
28
```python { .api }
29
def serve(panels, port=5006, show=False, **kwargs):
30
"""
31
Serve Panel applications on web server.
32
33
Parameters:
34
- panels: Panel object or dict of Panel objects to serve
35
- port: Port number for server (default: 5006)
36
- show: Whether to open browser automatically (default: False)
37
- allow_websocket_origin: List of allowed websocket origins
38
- autoreload: Enable automatic reloading on file changes
39
- **kwargs: Additional server configuration options
40
41
Returns:
42
Server object
43
"""
44
```
45
46
### Extension Configuration
47
48
Configures Panel extensions and global settings.
49
50
```python { .api }
51
def extension(*args, **kwargs):
52
"""
53
Configure Panel extensions and settings.
54
55
Parameters:
56
- *args: Extension names to load ('bokeh', 'plotly', 'tabulator', etc.)
57
- template: Default template to use
58
- theme: Theme name ('default', 'dark')
59
- sizing_mode: Default sizing mode
60
- **kwargs: Additional configuration options
61
"""
62
```
63
64
### Reactive Programming
65
66
Functions for creating reactive dependencies and binding parameters.
67
68
```python { .api }
69
def bind(function, *args, **kwargs):
70
"""
71
Bind function parameters for reactive programming.
72
73
Parameters:
74
- function: Function to bind
75
- *args: Positional arguments (can include Panel parameters)
76
- **kwargs: Keyword arguments (can include Panel parameters)
77
78
Returns:
79
Bound function that updates when parameters change
80
"""
81
82
def depends(*parameters):
83
"""
84
Declare parameter dependencies for functions.
85
86
Parameters:
87
- *parameters: Parameter objects or strings naming parameters
88
89
Returns:
90
Decorator function for dependency declaration
91
"""
92
```
93
94
### Interaction and Caching
95
96
Utilities for creating interactive UIs and caching function results.
97
98
```python { .api }
99
def interact(function, **kwargs):
100
"""
101
Create interactive UI from function parameters.
102
103
Parameters:
104
- function: Function to create UI for
105
- **kwargs: Parameter specifications for widgets
106
107
Returns:
108
Interactive Panel component
109
"""
110
111
112
def cache(func=None, **kwargs):
113
"""
114
Cache function results for performance.
115
116
Parameters:
117
- func: Function to cache (when used as decorator)
118
- **kwargs: Caching configuration options
119
120
Returns:
121
Cached function or decorator
122
"""
123
```
124
125
### Widget Integration
126
127
Convert Panel objects to other widget formats.
128
129
```python { .api }
130
def ipywidget(obj, **kwargs):
131
"""
132
Convert Panel objects to IPython widgets.
133
134
Parameters:
135
- obj: Panel object to convert
136
- **kwargs: Additional conversion parameters
137
138
Returns:
139
IPython widget equivalent
140
"""
141
```
142
143
## Global Configuration Objects
144
145
```python { .api }
146
class Config:
147
"""Global Panel configuration object with settings for themes, templates, and behavior"""
148
149
# Theme settings
150
theme: str
151
"""Current theme ('default', 'dark')"""
152
153
# Template settings
154
template: str
155
"""Default template name"""
156
157
# Sizing settings
158
sizing_mode: str
159
"""Default sizing mode ('fixed', 'stretch_width', 'stretch_height', 'stretch_both', 'scale_width', 'scale_height', 'scale_both')"""
160
161
class State:
162
"""Global application state manager for server-side state and caching"""
163
164
def add_periodic_callback(self, callback, period):
165
"""Add periodic callback to application"""
166
167
def remove_periodic_callback(self, callback):
168
"""Remove periodic callback from application"""
169
170
@property
171
def cache(self):
172
"""Access to application cache"""
173
```