\n",
"'''\n",
"HTML(summary_table_2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Step 2: Generate HTML report as a string and write to file"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This is the last step. We have all of the plots and tables that we want to include in the report - now we build an HTML string with the plots and tables embedded. Notice that the Bootstrap css library is included in the <head> for styling."
]
},
{
"cell_type": "code",
"execution_count": 184,
"metadata": {},
"outputs": [],
"source": [
"html_string = '''\n",
"\n",
" \n",
" \n",
" \n",
" \n",
" \n",
"
2014 technology and CPG stock prices
\n",
"\n",
" \n",
"
Section 1: Apple Inc. (AAPL) stock in 2014
\n",
" \n",
"
Apple stock price rose steadily through 2014.
\n",
" \n",
" \n",
"
Section 2: AAPL compared to other 2014 stocks
\n",
" \n",
"
GE had the most predictable stock price in 2014. IBM had the highest mean stock price. \\\n",
"The red lines are kernel density estimations of each stock price - the peak of each red lines \\\n",
"corresponds to its mean stock price for 2014 on the x axis.
\n",
"
Reference table: stock tickers
\n",
" ''' + summary_table_2 + '''\n",
"
Summary table: 2014 stock statistics
\n",
" ''' + summary_table_1 + '''\n",
" \n",
"'''"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally, write the html string to a local file."
]
},
{
"cell_type": "code",
"execution_count": 185,
"metadata": {},
"outputs": [],
"source": [
"f = open('/home/jack/report.html','w')\n",
"f.write(html_string)\n",
"f.close()"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already up-to-date: publisher in c:\\python36\\lib\\site-packages (0.11)\n"
]
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Python27\\lib\\site-packages\\IPython\\nbconvert.py:13: ShimWarning: The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead.\n",
" \"You should import from nbconvert instead.\", ShimWarning)\n",
"C:\\Python27\\lib\\site-packages\\publisher\\publisher.py:53: UserWarning: Did you \"Save\" this notebook before running this command? Remember to save, always save.\n",
" warnings.warn('Did you \"Save\" this notebook before running this command? '\n",
"C:\\Python27\\lib\\site-packages\\publisher\\publisher.py:58: UserWarning: Your URL has more than 2 parts... are you sure?\n",
" warnings.warn('Your URL has more than 2 parts... are you sure?')\n"
]
}
],
"source": [
"! pip install publisher --upgrade\n",
"\n",
"from IPython.display import HTML, display\n",
"\n",
"display(HTML(''))\n",
"display(HTML(''))\n",
"\n",
"import publisher\n",
"publisher.publish('html-reports', '/python/html-reports/', \n",
" 'Python HTML Reports', \n",
" 'How to make HTML reports with Python, Pandas, and Plotly Graphs.')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.14"
}
},
"nbformat": 4,
"nbformat_minor": 1
}