如何使用dash_html_components.Script命令

时间:2018-06-23 16:37:50

标签: plotly-dash

我想将下面的代码转换为破折号代码。 我可以知道如何将HTML代码中的第二个脚本标签转换为短划线吗?

.summary:hover+.detail,
.detail:hover {
  display: block;
}

.show.detail {
  display: block;
}

.detail {
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
  <a class="summary" href="javascript:void(0);">Sample1</a>
  <div class="detail">Detail of this summary</div>
</div>
<div class="wrapper">
  <a class="summary" href="javascript:void(0);">Sample2</a>
  <div class="detail">Detail of this summary</div>
</div>

<div class="wrapper">
  <a class="summary" href="javascript:void(0);">Sample3</a>
  <div class="detail">Detail of this summary</div>
</div>

<script>
  $(".summary").on("click", function() {
    $(this).next().toggleClass("show");
  })
</script>

1 个答案:

答案 0 :(得分:0)

您可以在plotly中建立相同的html结构。
以下代码是一个有效的示例。

要求:您的CSS代码必须存储在 static / stylesheet.css

示例:

import dash
import dash_core_components as dcc
import dash_html_components as html

from flask import send_from_directory
import os

app = dash.Dash(__name__)
server = app.server

# Configure Samples
sample1 = html.Div([
                dcc.Link('Sample1', href='javascript:void(0);', className='summary'),
                html.Div('Details of this summary', className='detail')
], className='wrapper')

sample2 = html.Div([
                dcc.Link('Sample2', href='javascript:void(0);', className='summary'),
                html.Div('Details of this summary', className='detail')
], className='wrapper')

sample3 = html.Div([
                dcc.Link('Sample3', href='javascript:void(0);', className='summary'),
                html.Div('Details of this summary', className='detail')
], className='wrapper')
# Define layout
app.layout = html.Div([
    sample1,
    sample2,
    sample3
])

app.scripts.append_script({"external_url": [
        "https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"
]})

# Add css file (locally hosted)
app.css.append_css({"external_url": [
    "static/stylesheet.css"
]})

# Serving local static files
@app.server.route('/static/<path:path>')
def static_file(path):
    static_folder = os.path.join(os.getcwd(), 'static')
    return send_from_directory(static_folder, path)

if __name__ == '__main__':
    app.run_server(debug=True)