本文整理匯總了Python中dash_html_components.Img方法的典型用法代碼示例。如果您正苦於以下問題:Python dash_html_components.Img方法的具體用法?Python dash_html_components.Img怎麽用?Python dash_html_components.Img使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dash_html_components
的用法示例。
在下文中一共展示了dash_html_components.Img方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: update_output
# 需要導入模塊: import dash_html_components [as 別名]
# 或者: from dash_html_components import Img [as 別名]
def update_output(contents):
if contents is not None:
content_type, content_string = contents.split(',')
if 'csv' in content_type:
df = pd.read_csv(io.StringIO(base64.b64decode(content_string).decode('utf-8')))
return html.Div([
dt.DataTable(rows=df.to_dict('records')),
html.Hr(),
html.Div('Raw Content'),
html.Pre(contents, style=pre_style)
])
elif 'image' in content_type:
return html.Div([
html.Img(src=contents),
html.Hr(),
html.Div('Raw Content'),
html.Pre(contents, style=pre_style)
])
else:
# xlsx will have 'spreadsheet' in `content_type` but `xls` won't
# have anything
try:
df = pd.read_excel(io.BytesIO(base64.b64decode(content_string)))
return html.Div([
dt.DataTable(rows=df.to_dict('records')),
html.Hr(),
html.Div('Raw Content'),
html.Pre(contents, style=pre_style)
])
except:
return html.Div([
html.Hr(),
html.Div('Raw Content'),
html.Pre(contents, style=pre_style)
])
示例2: layout
# 需要導入模塊: import dash_html_components [as 別名]
# 或者: from dash_html_components import Img [as 別名]
def layout(self) -> html.Img:
return html.Img(src=self.asset_url)
示例3: build_proj_hover_children
# 需要導入模塊: import dash_html_components [as 別名]
# 或者: from dash_html_components import Img [as 別名]
def build_proj_hover_children(proj):
if proj is None:
return None
return [
html.I(className="ico-help-outline", style=dict(color="white")),
html.Div(
[html.Div(proj), html.Img(src=build_img_src(proj))],
className="hoverable__content",
style=dict(width="auto"),
),
]
示例4: build_map_type_tabs
# 需要導入模塊: import dash_html_components [as 別名]
# 或者: from dash_html_components import Img [as 別名]
def build_map_type_tabs(map_type):
def _build_hoverable():
for t in MAP_TYPES:
if t.get("image", False):
yield html.Div(
[
html.Span(t.get("label", t["value"].capitalize())),
html.Img(src=build_img_src(t["value"], img_type="map_type")),
],
className="col-md-6",
)
return html.Div(
[
dcc.Tabs(
id="map-type-tabs",
value=map_type or "choropleth",
children=[
build_tab(t.get("label", t["value"].capitalize()), t["value"])
for t in MAP_TYPES
],
style=dict(height="36px"),
),
html.Div(
html.Div(list(_build_hoverable()), className="row"),
className="hoverable__content map-types",
),
],
style=dict(paddingLeft=15, borderBottom="none", width="20em"),
className="hoverable",
)
示例5: parse_contents
# 需要導入模塊: import dash_html_components [as 別名]
# 或者: from dash_html_components import Img [as 別名]
def parse_contents(contents, filename, date):
return html.Div([
html.H5(filename),
html.H6(datetime.datetime.fromtimestamp(date)),
# HTML images accept base64 encoded strings in the same format
# that is supplied by the upload
html.Img(src=contents),
html.Hr(),
html.Div('Raw Content'),
html.Pre(contents[0:200] + '...', style={
'whiteSpace': 'pre-wrap',
'wordBreak': 'break-all'
})
])
示例6: DisplayImagePIL
# 需要導入模塊: import dash_html_components [as 別名]
# 或者: from dash_html_components import Img [as 別名]
def DisplayImagePIL(id, image, **kwargs):
encoded_image = pil_to_b64(image, enc_format='png')
return html.Img(
id=f'img-{id}',
src=HTML_IMG_SRC_PARAMETERS + encoded_image,
width='100%',
**kwargs
)
示例7: create_app
# 需要導入模塊: import dash_html_components [as 別名]
# 或者: from dash_html_components import Img [as 別名]
def create_app(dir_name):
def encode(name):
path = os.path.join(
os.path.dirname(__file__),
'screenshots',
dir_name,
name
)
with open(path, 'rb') as image_file:
encoded_string = base64.b64encode(image_file.read())
return "data:image/png;base64," + encoded_string.decode('ascii')
# Define the app
app = dash.Dash(__name__)
app.layout = html.Div([
# represents the URL bar, doesn't render anything
dcc.Location(id='url', refresh=False),
# content will be rendered in this element
html.Div(id='page-content')
])
@app.callback(dash.dependencies.Output('page-content', 'children'),
[dash.dependencies.Input('url', 'pathname')])
def display_image(pathname): # pylint: disable=W0612
"""
Assign the url path to return the image it represent. For example,
to return "usage.png", you can visit localhost/usage.png.
:param pathname: name of the screenshot, prefixed with "/"
:return: An html.Img object containing the base64 encoded image
"""
if not pathname or pathname == '/':
return None
name = pathname.replace('/', '')
return html.Img(id=name, src=encode(name))
return app
示例8: get_logo
# 需要導入模塊: import dash_html_components [as 別名]
# 或者: from dash_html_components import Img [as 別名]
def get_logo():
logo = html.Div([
html.Div([
html.Img(src='http://logonoid.com/images/vanguard-logo.png', height='40', width='160')
], className="ten columns padded"),
html.Div([
dcc.Link('Full View ', href='/full-view')
], className="two columns page-view no-print")
], className="row gs-header")
return logo
示例9: build_banner
# 需要導入模塊: import dash_html_components [as 別名]
# 或者: from dash_html_components import Img [as 別名]
def build_banner():
return html.Div(
id="banner",
className="banner",
children=[
html.Img(src=app.get_asset_url("logo_programmer_a.png")),
html.H6("時空數據——時空分布動態"),
],
)
示例10: imageComponentBlock
# 需要導入模塊: import dash_html_components [as 別名]
# 或者: from dash_html_components import Img [as 別名]
def imageComponentBlock(
example_string,
location,
height=None,
width=400
):
'''Generate a container that is visually similar to the
ComponentBlock for components that require an externally hosted image.
:param (str) example_string: String containing the code that is
used in the application from the image.
:param (str) location: The URL of the image.
:param (int) height: The height of the image.
:param (int) width: The width of the image.
:rtype (dict): A dash_html_components div containing the code
container and the image.
'''
try:
exec(example_string, {})
except Exception as e:
print('\nError running\n{}\n{}'.format(
example_string,
('======================================' +
'======================================')
))
raise e
demo_location = re.match('.*pic_(.*)\.png\?raw=true', location)
if demo_location is not None:
demo_location = demo_location.group(1)
else:
demo_location = ''
return html.Div([
rc.Markdown(
'```python \n' + example_string + ' \n```',
style=styles.code_container
),
html.Div(
className='example-container',
children=[
dcc.Markdown(
'> Try a live demo at http://dash-gallery.plotly.host/docs-demos-dashbio/{}'.format(demo_location, demo_location)
),
html.Img(
style={'border': 'none', 'width': '75%', 'max-width': '500px'},
src=location
)
]
)
])
示例11: convert_to_html
# 需要導入模塊: import dash_html_components [as 別名]
# 或者: from dash_html_components import Img [as 別名]
def convert_to_html(component):
if component is None:
return ''
if not isinstance(component, Component):
# likely a str, int, float
return str(component)
component_dict = component.to_plotly_json()
if component_dict['type'] == 'Link':
component_dict['namespace'] = 'dash_html_components'
component_dict['type'] = 'A'
if component_dict['namespace'] != 'dash_html_components':
component = dcc_to_html(component)
component_dict = component.to_plotly_json()
tag = component_dict['type'].lower()
attrib_str = ['='.join([_translate_attrib(k).lower(),
'"{}"'.format(_translate_attrib(v))])
for k, v in component_dict['props'].items()
if _translate_attrib(k).lower()
not in ['style', 'children'] + bool_html_attrs]
attrib_str = ' '.join(attrib_str)
bool_str, style_str = '', ''
bool_attrs = []
for bool_attr in component_dict['props']:
if _translate_attrib(bool_attr).lower() in bool_html_attrs:
if bool(component_dict['props'][bool_attr]):
bool_attrs.append(_translate_attrib(bool_attr).lower())
bool_str = ' '.join(bool_attrs)
if 'style' in component_dict['props']:
style_str = 'style=' + _style_to_attrib(component_dict['props']['style'])
attrib_str = ' '.join([attrib_str, style_str, bool_str]).strip()
initial_indent = 0
comp_children = component_dict['props'].get('children', None)
if comp_children:
if isinstance(comp_children, (tuple, list)):
children = '\n' + '\n'.join([re.sub('^', '\g<0>' + (' ' * i if tag not in list_tags else ' ' * 2),
convert_to_html(child))
for i, child in enumerate(comp_children)])
else:
children = convert_to_html(comp_children)
else:
# e.g. html.Img doesn't have any children
children = ''
initial_indent += 2
closing_tag = '\n</{}>'.format(tag) if tag not in empty_tags else ''
attrib_str = ' ' + attrib_str if attrib_str else ''
return '<{}{}>{}{}'.format(tag, attrib_str, children, closing_tag)