def card(id: str, *, header: str, childs: list, app=None):
    @app.callback(Output(f'collapse-{id}',
                         'is_open'), [Input(f'toggle-{id}', 'n_clicks')],
                  [State(f'collapse-{id}', 'is_open')])
    def toggleButtonCallback(n_click, is_open):
        return not is_open if n_click else is_open

    return dbc.Card(id=id,
                    children=[
                        dbc.CardHeader(
                            html.H6(
                                dbc.Button(header,
                                           color="link",
                                           id=f'toggle-{id}',
                                           className='text-body'))),
                        dbc.Collapse(id=f'collapse-{id}',
                                     children=childs,
                                     style={
                                         'padding': '15px',
                                     }),
                    ],
                    className='shadow',
                    style={
                        'margin': '10px 0',
                    })
Esempio n. 2
0
def createRefreshComponent(app, componentId, callback):
    app.callback([
        Output('in-queue-list', 'children'),
        Output('in-progress-list', 'children'),
        Output('in-completed-list', 'children'),
        Output('in-aborted-list', 'children'),
    ], [Input(componentId, 'children')])(callback)

    return html.Div(id=componentId, style={'display': 'none'})
Esempio n. 3
0
def createCallbackForClick(app, inputsList, outputsList, statesList, func):
    outputsList = [Output(item['id'], item['prop'])
                   for item in outputsList] if len(outputsList) else None
    inputsList = [Input(item['id'], item['prop'])
                  for item in inputsList] if len(inputsList) else [None]
    statesList = [State(item['id'], item['prop'])
                  for item in statesList] if len(statesList) else [None]

    app.callback(outputsList, inputsList, statesList)(func)
Esempio n. 4
0
    def __init__(self, app):
        self.app = app

        self.app.layout = html.Div([
            html.Div("Redis Example"),
            html.Button(id='start-task-button', children=['Start Task']),
            html.Div(id='task-status')
        ])

        @self.app.callback(None, [Input('start-task-button', 'n_clicks')])
        def func(*args):
            worker = mp.Process(target=task, args=())
            worker.start()
Esempio n. 5
0
    def make(monitor, room):
        view = RoomView(monitor, room)

        @monitor.view.callback(Output(view.tank.id, 'max'),
                               [Input(view.input.id, 'value')])
        def update_max(value):
            try:
                room.occupancy_max = value
                return room.occupancy_max
            except Exception as e:
                print(e)
                raise (e)

        monitor.view.clientside_callback(
            """
            function(value, max) {
                if (value < max) {
                    return 'lightgreen';
                } else if (value == max) {
                    return 'lemonchiffon';
                } else {
                    return 'lightcoral';
                }
            }
            """, Output(view.tank.id, 'color'),
            [Input(view.tank.id, 'value'),
             Input(view.tank.id, 'max')])

        monitor.view.clientside_callback(
            """
            function(value, max) {
                return value + "/" + max + " people"
            }
            """, Output(view.label.id, 'children'),
            [Input(view.tank.id, 'value'),
             Input(view.tank.id, 'max')])

        return view
Esempio n. 6
0
    def __init__(self, app, connections):
        self.connections = connections

        @app.callback(
            None, [Input('command', 'n_clicks')],
            [State('input-on-submit', 'value'),
             State('actuator', 'value')])
        def command(n_clicks, value, actuator):
            command = self.connections.get('command', None)
            if command is not None:
                log.info(f'Sent: {actuator} {value}')
                command.send(json.dumps({actuator: value}))
            else:
                log.info(f'Cannot send command: No connection!')
Esempio n. 7
0
 def createCallbacks(self):
     @self.app.callback(
         Output({'type': 'abort-button', 'index': MATCH}, 'id'),
         [
             Input({'type': 'abort-button', 'index': MATCH}, 'n_clicks')
         ],
         [
             State({'type': 'abort-button', 'index': MATCH}, 'id'),
         ],
     )
     def f(n_clicks, buttonId):
         if (n_clicks):
             taskId = buttonId['index']
             self.wm.restartWorkerByTask(taskId)
             sp().updateTaskStatus(taskId, 'in-aborted')
         return buttonId
Esempio n. 8
0
    def __init__(self, app, mongo):
        self.config = Config()
        self.app = app
        self.mongo = mongo

        self.manager = NotificationManager()

        @app.callback(None, [Input('test_notifications', 'n_clicks')],
                      [State('test_notifications', 'value')])
        def test_notifications(n_clicks, value):
            if n_clicks > 0:
                print('Test')
                self.manager.text.text('Test!')
                self.manager.email.email(content='Test')
                print('Sent!')
                1 / 0
            else:
                pass
Esempio n. 9
0
def taskCard(app, info, submitButtonCallback):
    app.callback(None, [
        Input(f'start-button-{info["name"]}', 'n_clicks'),
    ], [
        State(f'input-rep-{info["name"]}', 'value'),
        State(f'file-uploader-{info["name"]}', 'contents'),
        State(f'{info["name"]}', 'id')
    ])(submitButtonCallback)

    collapseChildrenList = [
        Icc.upload(f'file-uploader-{info["name"]}', True),
        Icc.labelWithInput(f'input-rep-{info["name"]}',
                           'Number of repetitions:'),
        Icc.button(f'start-button-{info["name"]}', 'Start task')
    ]

    return Icc.card(info['name'],
                    info['header'],
                    collapseChildrenList,
                    app=app)
Esempio n. 10
0
 def callbacks(self):
     @app.callback(Output('tasklist', 'data'),
                   [Input('tabs-tasks', 'value')])
     def render_content(tab):
         return self.tasks_ended
Esempio n. 11
0
def taskCard(app, info, submitButtonCallback):
    @app.callback(Output(f'collapse-{info["name"]}', 'is_open'),
                  [Input(f'toggle-{info["name"]}', 'n_clicks')],
                  [State(f'collapse-{info["name"]}', 'is_open')])
    def toggleButtonCallback(n_click, is_open):
        return not is_open if n_click else is_open

    app.callback(None, [
        Input(f'start-button-{info["name"]}', 'n_clicks'),
    ], [
        State(f'input-rep-{info["name"]}', 'value'),
        State(f'file-uploader-{info["name"]}', 'contents'),
        State(f'{info["name"]}', 'id')
    ])(submitButtonCallback)
    # def func(n_clicks, reprValue, contents):
    #     print('!@#, Hello', n_clicks, reprValue, contents)

    collapseChildrenList = [
        dcc.Upload(id=f'file-uploader-{info["name"]}',
                   children=html.Div([
                       'Drag and Drop or ',
                       html.A('Select Files', className='text-primary')
                   ]),
                   style={
                       'height': '60px',
                       'lineHeight': '60px',
                       'borderWidth': '1px',
                       'borderStyle': 'dashed',
                       'borderRadius': '5px',
                       'textAlign': 'center',
                       'margin': '10px'
                   },
                   multiple=True),
        html.Label(children=[
            "Number of repetitions:",
            dcc.Input(id=f'input-rep-{info["name"]}',
                      type='number',
                      placeholder='>=1',
                      min=1,
                      style={
                          'margin-left': '20px',
                          'width': '60px',
                      }),
        ],
                   style={'margin-left': '10px'}),
        dbc.Button('Start task',
                   color='link',
                   id=f'start-button-{info["name"]}',
                   className='text-body bg-success',
                   style={
                       'display': 'block',
                       'margin': '10px auto',
                       'font-size': '1.2em'
                   }),
    ]

    return dbc.Card(id=info['name'],
                    children=[
                        dbc.CardHeader(
                            html.H6(
                                dbc.Button(info['header'],
                                           color="link",
                                           id=f'toggle-{info["name"]}',
                                           className='text-body'))),
                        dbc.Collapse(id=f'collapse-{info["name"]}',
                                     children=collapseChildrenList,
                                     style={
                                         'padding': '15px',
                                     }),
                    ],
                    className='shadow',
                    style={
                        'margin': '10px 0',
                    })
Esempio n. 12
0
def createBindingProgressComponent(app, componentId, callback):
    app.callback(None, [Input(componentId, 'children')], [
        State('in-progress-list', 'children'),
    ])(callback)

    return html.Div(id=componentId, style={'display': 'none'})
Esempio n. 13
0
def createBindingComponent(app, componentId, callback):
    app.callback(None, [Input(f'{componentId}', 'children')])(callback)

    return html.Div(id=f'{componentId}', style={'display': 'none'})
Esempio n. 14
0
                                     children=collapseChildrenList,
                                     style={
                                         'padding': '15px',
                                     }),
                    ],
                    className='shadow',
                    style={
                        'margin': '10px 0',
                    })


def createReportList(app, /, listId='empty-id', listName='empty name'):
    @app.callback([
        Output(f'{listId}-p', 'children'),
        Output(f'{listId}-wrapper', 'style')
    ], [Input(f'{listId}-list', 'children')])
    def func(childList):
        return f'Task count: {len(childList)}', {
            'display': 'none'
        } if len(childList) == 0 else {
            'display': 'block'
        }

    return html.Div(
        id=f'{listId}-wrapper',
        children=[
            html.Div(children=[
                html.H6(listName,
                        style={'margin': '10px 0'},
                        className='text-primary'),
                html.P(id=f'{listId}-p', className='text-secondary')
Esempio n. 15
0
    def __init__(self, app, mongo):
        self.config = Config()
        self.app = app
        self.mongo = mongo
        self.scraper = PlantScraper(mongo)

        @app.callback(None, [Input('remove_plant', 'n_clicks')], [
            State('remove_plant', 'value'),
            State('plant_name', 'value'),
            State('x_coordinate', 'value'),
            State('y_coordinate', 'value'),
            State('sensor_id', 'value')
        ])
        def remove_plant(n_clicks, button_value, plant_name, x, y, sensor):
            if n_clicks > 0:
                print(f'Removing plant!!: {plant_name} ({x}, {y})')
                self.mongo.plants.list.remove(dict(name=plant_name, x=x, y=y),
                                              dict(justOne=True))
            return self.plot_plants()

        @app.callback(Output('plant_map', 'figure'),
                      [Input('add_plant', 'n_clicks')], [
                          State('add_plant', 'value'),
                          State('plant_name', 'value'),
                          State('x_coordinate', 'value'),
                          State('y_coordinate', 'value'),
                          State('sensor_id', 'value')
                      ])
        def add_plant(n_clicks, button_value, plant_name, x, y, sensor):
            if n_clicks > 0:
                print(f'Adding plant!!: {plant_name} ({x}, {y})')
                n = self.mongo.plants.list.count()
                self.mongo.plants.list.insert_one(
                    dict(name=plant_name, x=x, y=y, sensor=sensor, n=n))
            else:
                pass
            return self.plot_plants()

        @app.callback(Output('description', 'children'),
                      [Input('add_plant', 'n_clicks')], [
                          State('add_plant', 'value'),
                          State('plant_name', 'value'),
                          State('x_coordinate', 'value'),
                          State('y_coordinate', 'value')
                      ])
        def update_description(n_clicks, button_value, plant_name, x, y):
            if n_clicks > 0:
                entry = self.scraper.get(plant_name)
                return P(entry['summary'])
            else:
                return P(
                    'When new plants are added, wikipedia entries about them will appear here'
                )

        @app.callback(Output('needs_description', 'children'),
                      [Input('add_plant', 'n_clicks')], [
                          State('add_plant', 'value'),
                          State('plant_name', 'value'),
                          State('x_coordinate', 'value'),
                          State('y_coordinate', 'value')
                      ])
        def update_description(n_clicks, button_value, plant_name, x, y):
            if n_clicks > 0:
                entry = self.scraper.get(plant_name)
                latin = entry['latin_name']
                common = entry['common_name'][0]
                habitat = entry['habitat']
                height = entry['height']
                soil = ' or '.join(entry['soil'])
                shade = ' or '.join(s if s != 'none' else 'no'
                                    for s in entry['shade'])
                moist = ' or '.join(entry['moisture'])

                description = f'''The {latin}, or {common} lives in a {habitat} habitat, grows to around {height}m, prefers {soil} and {moist} soil with {shade} shade'''

                return P(description)
            else:
                return P(
                    'When new plants are added, wikipedia entries about them will appear here'
                )