Beispiel #1
0
def test_auth():
    """Test API-based auth"""
    TEST_ENV = "test_env"

    fp = c.get_config_file(TEST_ENV)
    if fp.exists():
        fp.unlink()

    try:
        dp.init(config_env=TEST_ENV)

        # check the config env file is default
        assert fp.read_text() == c.get_default_config()

        with pytest.raises(InvalidTokenError):
            dp.ping()

        # login
        dp.login(token=TEST_TOKEN,
                 server=TEST_SERVER,
                 env=TEST_ENV,
                 cli_login=False)
        dp.ping()
        # logout
        dp.logout(env=TEST_ENV)

        # check we've reset the config env file back to default
        assert fp.read_text() == c.get_default_config()

        with pytest.raises(InvalidTokenError):
            dp.ping()
    finally:
        if fp.exists():
            fp.unlink()
Beispiel #2
0
def publish_report(df: pandas.DataFrame):
    dp_token: str = db["DP_TOKEN"]
    dp.login(token=dp_token)

    plot = alt.Chart(df).mark_area(opacity=0.4, stroke='black').encode(
        x='date:T',
        y=alt.Y('new_cases_smoothed_per_million:Q', stack=None),
        color=alt.Color('continent:N', scale=alt.Scale(scheme='set1')),
        tooltip='continent:N').interactive().properties(width='container')

    dp.Report(dp.Plot(plot), dp.DataTable(df)).save(path='report.html',open=True)
Beispiel #3
0
def test_auth():
    """Test API-based auth"""
    TEST_ENV = "test_env"

    fp: Optional[Path] = None
    try:
        dp.init(config_env=TEST_ENV)

        config = c.get_config()
        fp = config._path

        # check the config env file can't login and is the default
        assert config.token == c.DEFAULT_TOKEN
        with pytest.raises(InvalidTokenError):
            dp.ping()

        # login
        username = dp.login(token=TEST_TOKEN,
                            server=TEST_SERVER,
                            env=TEST_ENV,
                            cli_login=False)
        assert username == "datapane-test"
        # logout
        dp.logout(env=TEST_ENV)

        # check we've remove the config env file
        assert not fp.exists()

    finally:
        if fp and fp.exists():
            fp.unlink()
Beispiel #4
0
import altair as alt
import pandas as pd
import datapane as dp
import numpy as np
import plotly.express as px
import plotly.figure_factory as ff
import plotly.graph_objects as go
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets

# Sign-in with your unique token
dp.login(token="a7f3b829ac6a2e8d3c1d15c0f5544f88e1031acf")

dataset = pd.read_csv('data/au19.csv')

html = """
<html>
    <style type='text/css'>
        @keyframes example {
            0%   {color: #EEE;}
            25%  {color: #EC4899;}
            50%  {color: #8B5CF6;}
            100% {color: #EF4444;}
        }
        #container {
            background: #1F2937;
            padding: 10em;
        }
        h1 {
            color:#eee;
            animation-name: example;
Beispiel #5
0
import altair as alt
import pandas as pd
import datapane as dp
from datetime import date
from folium import plugins
import folium
import plotly.express as px
import sys

import plotly.io as pio
pio.templates.default = "plotly_dark"

token_datapane = sys.argv[1]

dp.login(token=token_datapane)

cidades = pd.read_csv("cidades.csv")
df_vagas = pd.read_csv("vagas-ds.csv")

df_AD = df_vagas.loc[df_vagas.vaga == 'analista de dados']
df_CD = df_vagas.loc[df_vagas.vaga == 'cientista de dados']
df_ED = df_vagas.loc[df_vagas.vaga == 'engenheiro de dados']
df_EML = df_vagas.loc[df_vagas.vaga == 'engenheiro de machine learning']
colunas = ['Local', 'Empresa', 'Descricao', 'Link']

df_AD.reset_index(drop=True, inplace=True)
df_CD.reset_index(drop=True, inplace=True)
df_ED.reset_index(drop=True, inplace=True)
df_EML.reset_index(drop=True, inplace=True)