예제 #1
0
def generate_table(df, max_rows=26):
    """
	Generate an HTML table for a DataFrame using Dash HTML components. Taken from: https://stackoverflow.com/questions/52213738/html-dash-table
	
	Parameters
	----------
	df : pd.DataFrame
		The DataFrame to convert into an HTML table.
	max_rows : int, optional
		The maximum number of rows to output into the table.
	
	Returns
	-------
	html.Table
		The HTML version of the given DataFrame.
	
	"""

    table = [html.Caption("Tracked Aircraft")
             ] + [html.Tr([html.Th(col) for col in df.columns])] + [
                 html.Tr([html.Td(df.iloc[i][col]) for col in df.columns])
                 for i in range(min(len(df), max_rows))
             ]

    return html.Table(children=table)
예제 #2
0
def failed_samples_table(caption,failed_samples):
   if not isinstance(failed_samples, list):
      raise TypeError( "failed_samples is {}, should be a list".format(type(failed_samples)) )
   table_rows =   [  html.Tr([
                        html.Th('Lane'),
                        html.Th('Stage'),
                        html.Th('Issue'),
                        ])
                     ]+[
                        # this row repeated for each failed sample
                        html.Tr( children = [
                                    html.Td( f['lane'] ),
                                    html.Td( f['stage'] ),
                                    html.Td( f['issue'] ),
                                    ]
                                 )
                        for f in failed_samples
                     ]
   elements = [   html.Table(
                     className   = 'failed_samples_table',
                     children    = [   html.Caption(caption),
                                       html.Tbody(table_rows)
                                       ]
                     )
                  ]
   return elements
def _gen_text_table(links, is_mustlink):
    if len(links) == 0:
        return html.Table()

    return html.Table(
        # Caption on top
        [html.Caption('List of {}'.format('Must-links' if is_mustlink else 'Cannot-links'),
                      style={'caption-side': 'top', 'text-align': 'center', 'color': 'black'})] +
        # Header
        [html.Tr([html.Th('#'),
                  html.Th('Instance 1'), html.Th('Instance 2')])] +
        # Body
        [html.Tr([
            html.Td(len(links) - i),
            html.Td(target_names[i1][:60]),
            html.Td(target_names[i2][:60]),
        ]) for i, [i1, i2] in enumerate(links[::-1])],
        # bootstrap css
        style={
            'color': '#007bff' if is_mustlink else '#545b62',
            'vertical-align': 'middle',
            'text-align': 'center'
        },
        className="table table-sm"
    )
def _gen_img_table(links, is_mustlink):
    if len(links) == 0:
        return html.Table()

    img_path = '{}/{}.svg'.format(static_host, dataset_name)
    return html.Table(
        # Caption on top
        [html.Caption('List of {}'.format('Must-links' if is_mustlink else 'Cannot-links'),
                      style={'caption-side': 'top', 'text-align': 'center', 'color': 'black'})] +
        # Header
        [html.Tr([html.Th('#'), html.Th('Image 1'), html.Th('Image 2')])] +
        # Body
        [html.Tr([
            html.Td(len(links) - i),
            html.Td(html.Img(src='{}#{}'.format(img_path, i1), height=32)),
            html.Td(html.Img(src='{}#{}'.format(img_path, i2), height=32)),
        ]) for i, [i1, i2] in enumerate(links[::-1])],
        # bootstrap css
        style={
            'color': '#007bff' if is_mustlink else '#545b62',
            'vertical-align': 'middle',
            'text-align': 'center'
        },
        className="table table-sm"
    )
def generate_tabel(df, title):
    return html.Table([
        html.Caption(title),
        html.Tbody([
            html.Tr([html.Td(df.iloc[i][col]) for col in df.columns])
            for i in range(len(df))
        ])
    ])
예제 #6
0
def samples_received_table(this_institution, params):
   this_batch = params['batches'][this_institution]
   if not isinstance(this_batch, dict):
      raise TypeError( "params.batches.{} is {}, should be a dict".format(k,type(this_batch)) )
   for required_int in ['expected', 'received']:
      if not isinstance(this_batch[required_int], int):
         raise TypeError( "params.batches.{}.{} is {}, should be a int".format(k,required_int,type(this_batch[required_int])) )
   if not isinstance(this_batch['deliveries'], list):
      raise TypeError( "params.batches.{}.deliveries is {}, should be a list".format(k,type(this_batch['deliveries'])) )
   for this_delivery in this_batch['deliveries']:
      if not isinstance(this_delivery, dict):
         raise TypeError( "params.batches.{}.deliveries contains a {}, should be a dict".format(k,type(this_delivery)) )
   elements = [   html.Table(
                     className   = 'samples_received_table',
                     children    = [   html.Caption('Samples Received'),
                                       html.Tbody([
                                          html.Tr([
                                             html.Td(
                                                colSpan     = 3,
                                                className   = 'status_desc',
                                                children    = ['Of the ~{} samples expected:'.format(this_batch['expected'])],
                                                ),
                                             html.Td( 
                                                rowSpan     = len(this_batch['deliveries'])+2,
                                                className   = 'per_cent_gauge',
                                                children    = progress_gauge(this_batch['received'], this_batch['expected']),
                                                ),
                                             ])
                                          ]+[
                                             # this row repeated for each batch
                                             html.Tr( children = [
                                                         html.Td( b['name'],   className = 'text_column' ),
                                                         html.Td( b['date'],   className = 'text_column' ),
                                                         html.Td( b['number'], className='numeric' ),
                                                         ]
                                                      )
                                             for b in this_batch['deliveries']
                                          ]+[
                                          html.Tr([
                                             html.Td( 'total received:', colSpan=2, className = 'text_column centered' ),
                                             html.Td( this_batch['received'], className='numeric' ),
                                             ]),
                                          ]+[
                                          html.Tr([
                                             html.Td( 
                                                colSpan     = 4,
                                                className   = 'text_column centered compact tiny_text',
                                                children    = [params['updated'].strftime( '%H:%M:%S.%f' )],
                                                ),
                                             ]),
                                          ]),
                                       ]
                     )
                  ]
   return elements
예제 #7
0
def model_layout(figure, table):
    return [
        html.Center([
            dcc.Graph(figure=figure),
            html.Table([
                html.Caption('Error Values Obtained for the Model'),
                html.Thead(html.Tr([
                    html.Th('MAE', className='th'),
                    html.Th('MSE', className='th'),
                    html.Th('RMSE', className='th'),
                    html.Th('cvRMSE', className='th')
                ]),
                           className='th'),
                html.Tbody([
                    html.Tr([
                        html.Td(round(row, 2), className='td')
                        for row in error_values.iloc[table, 2:]
                    ])
                ])
            ],
                       className='table')
        ])
    ]
# Define the app
app.layout = html.Div(children=[
    html.Div(
        id='top-bar',
        className='top-bar',
        children=[
            html.Img(src='data: image/png;base64,{}'.format(
                encoded_image_twt.decode()),
                     height='50vh'),
            html.
            H3('Short Text Topic Modeling on Health-Related Tweets Dashboard'),
            html.Caption(children=[
                html.A(children=[
                    html.Img(src='data: image/png;base64,{}'.format(
                        encoded_image_git.decode()),
                             height='25vh')
                ],
                       href=
                       'https://github.com/bicachu/topic-modeling-health-tweets'
                       )
            ])
        ]),
    html.Div(
        className='body',
        children=[
            html.Div(
                className='three columns',
                children=[
                    html.Div(
                        className='nav-panel bg-lightgrey',
                        children=[
                            dcc.Tabs(
예제 #9
0
                             ],color="dark", outline=True),
                             #width=5,
                             )
                      ],no_gutters=False,style={ "border-style": "dash"},justify="center",)
         
        ], style={ "border-style": "hidden",
                  "width":"auto",
                  "background-color":"white"}, fluid =True)
    
   ]
table_header = [
    html.Thead(html.Tr([ html.Th('Symbol' ),html.Th('Quantity'),html.Th('Bought Price'),html.Th('Date')]))
]                      
sample_row = html.Tr([html.Td("Dis"), html.Td("10"), html.Td("100"), html.Td("2018-08-06")])
table_body = [html.Tbody([sample_row])]
table_caption = [html.Caption("Sample format for the file")]

app.layout = html.Div([
    
    html.Div(
        [
     html.Div(dcc.Markdown('''
                  Welcome! Visualize your portfolio now!
                  Upload your portfolio file using the format described below and get started. Use this tool to analyze your portfolio. 
                  ''' , style={'padding':'5px','height':'auto'}), style={'position': 'relative',
                                                                      'top': '45px', 'height':'auto'})
    ,html.Br()
    
    ,html.Div(id='portfolio file description', children=dbc.Table(table_caption + table_header + table_body , bordered=True,style={
                'width': '95%',
                'height':'10px',
예제 #10
0
def pipeline_table(this_institution, params):
   this_status    = params['pipeline_status'][this_institution]
   if not isinstance(this_status, dict):
      raise TypeError( "params.pipeline_status is {}, should be a dict".format(k,type(this_status)) )
   for required_int in ['running', 'completed', 'success', 'failed']:
      if not isinstance(this_status[required_int], int):
         raise TypeError( "params.pipeline_status.{}.{} is {}, should be a int".format(this_institution,required_int,type(this_status[required_int])) )
   if not isinstance(this_status['fail_messages'], list):
      raise TypeError( "params.pipeline_status.{}.fail_messages is {}, should be a list".format(this_institution,type(this_status['fail_messages'])) )
   # we need to know the number of successfully sequenced lanes, as that's the number we expect to go through the pipelines
   num_seq_success = params['sequencing_status'][this_institution]['success']
   # some elements are not displayed/disabled if there are no related samples 
   if not this_status['success'] > 0:
      display_success_download = 'none';
   else:
      display_success_download = 'table-cell';
   if not this_status['failed'] > 0:
      toggle_disabled         = True;
      display_failed_download = 'none';
   else:
      toggle_disabled         = False;
      display_failed_download = 'table-cell';
   elements = [   html.Table(
                     className   = 'pipeline_table',
                     children    = [   html.Caption('Pipeline Status'),
                                       html.Tbody([
                                          html.Tr([
                                             html.Td(
                                                colSpan     = 4,
                                                className   = 'status_desc',
                                                children    = ['Of the {} samples successfully sequenced:'.format(num_seq_success)]
                                                ),
                                             html.Td( 
                                                rowSpan     = 5,
                                                className   = 'per_cent_gauge',
                                                children    = progress_gauge(this_status['completed'], num_seq_success),
                                                ),
                                             ]),
                                          html.Tr([
                                             html.Td( 'Waiting', colSpan  = 2, className = 'text_column' ),
                                             html.Td( num_seq_success-(this_status['running']+this_status['completed']), className='numeric' ),
                                             html.Td(), # no download currently
                                             ]),
                                          html.Tr([
                                             html.Td( 'Running', colSpan  = 2, className = 'text_column' ),
                                             html.Td( this_status['running'], className='numeric' ),
                                             html.Td(), # no download currently
                                             ]),
                                          html.Tr([
                                             html.Td( 'Completed', colSpan  = 2, className = 'text_column' ),
                                             html.Td( this_status['completed'], className='numeric' ),
                                             html.Td(), # no download currently
                                             ]),
                                          html.Tr([
                                             html.Td( ),
                                             html.Td( 'Success', className = 'text_column' ),
                                             html.Td( this_status['success'], className='numeric' ),
                                             html.Td( download_button(  params['app'],
                                                                        "download {} samples successfully processed through the pipeline".format(this_status['success']),
                                                                        params['institutions'][this_institution]['db_key'],
                                                                        'pipeline',
                                                                        'successful',
                                                                        ),
                                                      className   = 'download',
                                                      style       = {'display': display_success_download},
                                                      ),
                                             ]),
                                          html.Tr([
                                             html.Td( ),
                                             html.Td( html.Div(className   = 'aligned_button_container',
                                                               children    = ['Failed ',
                                                                              daq.ToggleSwitch(id           = {'type':  params['pipeline_callback_input_type'],
                                                                                                               'index': this_institution
                                                                                                               },
                                                                                                className   = 'toggle_switch',
                                                                                                disabled    = toggle_disabled,
                                                                                                size        =  30,
                                                                                                value       =  False
                                                                                                ),
                                                                              ],
                                                               ),
                                                      className = 'text_column'
                                                      ),
                                             html.Td( this_status['failed'], className='numeric' ),
                                             html.Td( download_button(  params['app'],
                                                                        "download {} failed samples".format(this_status['failed']),
                                                                        params['institutions'][this_institution]['db_key'],
                                                                        'pipeline',
                                                                        'failed',
                                                                        ),
                                                      className   = 'download',
                                                      style       = {'display': display_failed_download},
                                                      ),
                                             ]),
                                          ]),
                                       ]
                     ),
                  ]
   return elements
예제 #11
0
                          'overflowY': 'scroll',
                          'maxHeight': '330px',
                          'backgroundColor': colors['background'],
                          'color': colors['background']
                      },
                      style_header={
                          'backgroundColor': '#b3cde0',
                          'fontWeight': 'bold',
                          'textAlign': 'center'
                      }),
 html.Caption('Data from New York Times - Updated at ' + str(
     datetime.datetime.strftime(datetime.datetime.now(),
                                '%Y-%m-%d %I:%M:%S %p' + ' ET')),
              style={
                  'font': 'Helvetica',
                  'font-style': 'italic',
                  'font-weight': 'light',
                  'white-space': 'nowrap',
                  'overflowY': 'hidden',
                  'color': colors['text']
              }),
 html.Br(),
 html.H4(children='Reported Cases by US State/Territory',
         style={
             'textAlign': 'center',
             'color': colors['text'],
             'font': 'Helvetica'
         }),
 html.Br(),
 dcc.Graph(id='cases-by-state-chloropleth',
           figure=cases_by_state_chloropleth,
예제 #12
0
def map_pointer_table(
    config,
    climate_regime,
    design_value_ids,
    dataset_ids,
    data_values,
    selected_dv=None,
    selected_dataset_id=None,
):
    """
    Return a table listing values of design values at a location specified
    by rotated coordinates rlon, rlat
    """
    if climate_regime == "historical":
        # TODO: These label(s) should be defined in config
        # value_headers = tuple(
        #     f"{dataset_id.capitalize()} value" for dataset_id in dataset_ids
        # )
        value_headers = ("Interpolation value", )
    else:
        value_headers = tuple(
            future_change_factor_label(config, dataset_id)
            for dataset_id in dataset_ids)

    return dbc.Table(
        [
            html.Caption(climate_regime_label(config, climate_regime),
                         style={
                             "caption-side": "top",
                             "padding": "0 0 0.5em 0"
                         }),
            html.Thead(
                html.Tr([
                    html.Th(hdg) for hdg in (
                        tuple(config["ui"]["labels"]["download_table"][k]
                              for k in ("dv", "units")) + value_headers)
                ])),
            html.Tbody([
                html.Tr([
                    html.Th(dv_name(config, design_value_id)),
                    html.Th(
                        dv_units(config, design_value_id, climate_regime),
                        style={"width": "5em"},
                    ),
                ] + [
                    html.Td(
                        round_to_multiple(
                            data_value,
                            dv_roundto(config, design_value_id,
                                       climate_regime),
                        ),
                        style={
                            "color":
                            "red" if design_value_id == selected_dv and
                            dataset_id == selected_dataset_id else "inherit"
                        },
                    ) for dataset_id, data_value in zip(dataset_ids, data_row)
                ]) for design_value_id, data_row in zip(
                    design_value_ids, data_values)
            ]),
        ],
        bordered=True,
        size="sm",
    )