Google picker component for dash
Project description
Dash Google Picker
The dash_google_picker is a Python module that allows the integration of Google's Picker API with a Dash application. The module provides a Dash component GooglePicker to easily implement the Google Picker functionality into your application, enabling your users to select files from their Google Drive account, among other data sources.
Features
- Leverages Google Picker API for seamless integration with Google Drive.
- Allows selection of multiple files from Google Drive.
- Customizable views and features according to Google Picker API.
Documentation
Installation
Use pip to install the package:
pip install dash-google-picker
Prerequisites
Follow the official Google Picker Guide to create the required credentials.
Usage
The usage example below shows how to use the GooglePicker component in your Dash application.
from typing import List
from dash import Dash, dcc, html, Input, Output, State, dcc
from dash_google_picker import GooglePicker
from dash_google_picker.Documents import GoogleDocuments, GoogleDocument
import os
app = Dash(__name__)
app.layout = html.Div([
html.Button('Open Google Picker', id='open-picker-button', n_clicks=0),
GooglePicker(
id='google-picker',
client_id='GOOGLE_CLIENT_ID',
developer_key='GOOGLE_DEVELOPER_KEY'
),
dcc.Markdown(id='display-documents', style={'whiteSpace': 'pre-wrap'}),
html.Div(id='display-action')
])
if __name__ == '__main__':
app.run_server(debug=True)
The picker view can be customised, for more information see the GooglePicker component documentation or the Google Picker API Documentation.
Callbacks
The GooglePicker component generates two outputs documents and action. The documents output contains a list of documents selected by the user, and action contains the current action status.
@app.callback(
Output('google-picker', 'open'),
[Input('open-picker-button', 'n_clicks')],
[State('google-picker', 'open')]
)
def open_google_picker(n_clicks, is_open):
if n_clicks > 0:
return not is_open
return False
@app.callback(
Output('display-documents', 'children'),
[Input('google-picker', 'documents')],
prevent_initial_call=True
)
def display_output(documents):
docs : List[GoogleDocument] = GoogleDocuments(documents)
x = "\n".join([f"{prop}: {getattr(obj, prop)}" for obj in docs for prop in dir(obj) if not prop.startswith("__")])
return x
@app.callback(
Output('display-action', 'children'),
[Input('google-picker', 'action')],
prevent_initial_call=True
)
def display_action(action):
if action == "loaded":
return "Opened the Google Picker Popup"
elif action == "picked":
return "Picked a document"
elif action == "cancelled":
return "Cancelled the Google Picker Popup"
return f'Action: {action}'
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dash_google_picker-1.1.0-py3-none-any.whl.
File metadata
- Download URL: dash_google_picker-1.1.0-py3-none-any.whl
- Upload date:
- Size: 19.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
753bae4cd461720f3f64eb78b04c6e548d28f07498bf715f265648f3c76203d9
|
|
| MD5 |
4d83f89e7a89ebbf37ecc475beb68f4f
|
|
| BLAKE2b-256 |
219b70067fc2f068a0ab0112f08ddd701816b0c22eed9fc61de076ada44d28b9
|