100% found this document useful (1 vote)
45 views

Web App Development and Real-Time Web Analytics With Python: Develop and Integrate Machine Learning Algorithms Into Web Apps Nokeri

Develop

Uploaded by

fernsobiba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
45 views

Web App Development and Real-Time Web Analytics With Python: Develop and Integrate Machine Learning Algorithms Into Web Apps Nokeri

Develop

Uploaded by

fernsobiba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

Full download ebooks at ebookmeta.

com

Web App Development and Real-Time Web Analytics


with Python: Develop and Integrate Machine
Learning Algorithms into Web Apps Nokeri

https://ebookmeta.com/product/web-app-development-and-real-
time-web-analytics-with-python-develop-and-integrate-
machine-learning-algorithms-into-web-apps-nokeri/

OR CLICK BUTTON

DOWLOAD NOW

Download more ebook from https://ebookmeta.com


More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Real-Time Twilio and Flybase. Build Real-Time Web Apps


Using Twilio and Flybase with Node.js 1st Edition Roger
Stringer

https://ebookmeta.com/product/real-time-twilio-and-flybase-build-
real-time-web-apps-using-twilio-and-flybase-with-node-js-1st-
edition-roger-stringer/

Web Development with Clojure Build Bulletproof Web Apps


with Less Code 3rd Edition Dmitri Sotnikov Scot Brown

https://ebookmeta.com/product/web-development-with-clojure-build-
bulletproof-web-apps-with-less-code-3rd-edition-dmitri-sotnikov-
scot-brown/

Web Application Development with Streamlit: Develop and


Deploy Secure and Scalable Web Applications to the
Cloud Using a Pure Python Framework 1st Edition
Mohammad Khorasani
https://ebookmeta.com/product/web-application-development-with-
streamlit-develop-and-deploy-secure-and-scalable-web-
applications-to-the-cloud-using-a-pure-python-framework-1st-
edition-mohammad-khorasani/

Real-Time Web Application Development: With ASP.NET


Core, SignalR, Docker, and Azure 1st Edition Rami
Vemula

https://ebookmeta.com/product/real-time-web-application-
development-with-asp-net-core-signalr-docker-and-azure-1st-
edition-rami-vemula/
High-Performance Web Apps with FastAPI: The
Asynchronous Web Framework Based on Modern Python 1st
Edition Malhar Lathkar

https://ebookmeta.com/product/high-performance-web-apps-with-
fastapi-the-asynchronous-web-framework-based-on-modern-
python-1st-edition-malhar-lathkar/

High-Performance Web Apps with FastAPI: The


Asynchronous Web Framework Based on Modern Python 1st
Edition Malhar Lathkar

https://ebookmeta.com/product/high-performance-web-apps-with-
fastapi-the-asynchronous-web-framework-based-on-modern-
python-1st-edition-malhar-lathkar-2/

Learning Progressive Web Apps 1st Edition John Wargo

https://ebookmeta.com/product/learning-progressive-web-apps-1st-
edition-john-wargo/

Beginning Azure Static Web Apps: Building and Deploying


Dynamic Web Applications with Blazor 1st Edition Stacy
Cashmore

https://ebookmeta.com/product/beginning-azure-static-web-apps-
building-and-deploying-dynamic-web-applications-with-blazor-1st-
edition-stacy-cashmore/

Beginning Azure Static Web Apps: Building and Deploying


Dynamic Web Applications with Blazor 1st Edition Stacy
Cashmore

https://ebookmeta.com/product/beginning-azure-static-web-apps-
building-and-deploying-dynamic-web-applications-with-blazor-1st-
edition-stacy-cashmore-2/
Web App Development
and Real-Time Web
Analytics with Python
Develop and Integrate Machine Learning
Algorithms into Web Apps

Tshepo Chris Nokeri
Web App Development
and Real-Time Web
Analytics with Python
Develop and Integrate Machine
Learning Algorithms into Web Apps

Tshepo Chris Nokeri


Web App Development and Real-Time Web Analytics with Python: Develop and
Integrate Machine Learning Algorithms into Web Apps

Tshepo Chris Nokeri


Pretoria, South Africa

ISBN-13 (pbk): 978-1-4842-7782-9 ISBN-13 (electronic): 978-1-4842-7783-6


https://doi.org/10.1007/978-1-4842-7783-6

Copyright © 2022 by Tshepo Chris Nokeri


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Celestin Suresh John
Development Editor: James Markham
Coordinating Editor: Mark Powers
Cover designed by eStudioCalamar
Cover image by Andrew Kliatskyi on Unsplash (www.unsplash.com)
Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004,
U.S.A. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or visit www.
springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science
+ Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected]; for reprint,
paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/9781484277829. For more
detailed information, please visit http://www.apress.com/source-­code.
Printed on acid-free paper
I would like dedicate this book to my family, friends, and
anyone who played a pivotal role in any aspect of my life,
including the Apress team for the continous support.
Table of Contents
About the Author����������������������������������������������������������������������������������������������������� xi

About the Technical Reviewer������������������������������������������������������������������������������� xiii


Acknowledgments���������������������������������������������������������������������������������������������������xv

Chapter 1: Tabulating Data and Constructing Static 2D and 3D Charts�������������������� 1


Tabulating the Data����������������������������������������������������������������������������������������������������������������������� 1
2D Charting����������������������������������������������������������������������������������������������������������������������������������� 4
Box-Whisker Plot��������������������������������������������������������������������������������������������������������������������� 6
Histogram�������������������������������������������������������������������������������������������������������������������������������� 7
Line Plot����������������������������������������������������������������������������������������������������������������������������������� 8
Scatter Plot������������������������������������������������������������������������������������������������������������������������������ 9
Density Plot��������������������������������������������������������������������������������������������������������������������������� 10
Violin Plot������������������������������������������������������������������������������������������������������������������������������� 11
Regression Plot��������������������������������������������������������������������������������������������������������������������� 13
Joint Plot������������������������������������������������������������������������������������������������������������������������������� 13
Heatmap�������������������������������������������������������������������������������������������������������������������������������� 14
3D Charting��������������������������������������������������������������������������������������������������������������������������������� 17
Conclusion���������������������������������������������������������������������������������������������������������������������������������� 19

Chapter 2: Interactive Tabulation and Charting������������������������������������������������������ 21


Plotly������������������������������������������������������������������������������������������������������������������������������������������� 21
Tabulating the Data with Plotly��������������������������������������������������������������������������������������������������� 22
Interactive Charting��������������������������������������������������������������������������������������������������������������������� 23
2D Charting��������������������������������������������������������������������������������������������������������������������������������� 23
Box Plot��������������������������������������������������������������������������������������������������������������������������������� 26
Violin Plot������������������������������������������������������������������������������������������������������������������������������� 27
Histogram������������������������������������������������������������������������������������������������������������������������������ 28

v
Table of Contents

Scatter Plot���������������������������������������������������������������������������������������������������������������������������� 32
Density Plot��������������������������������������������������������������������������������������������������������������������������� 34
Bar Chart������������������������������������������������������������������������������������������������������������������������������� 36
Pie Chart�������������������������������������������������������������������������������������������������������������������������������� 38
Sunburst�������������������������������������������������������������������������������������������������������������������������������� 38
Choropleth Map��������������������������������������������������������������������������������������������������������������������������� 41
Heatmap�������������������������������������������������������������������������������������������������������������������������������� 42
3D Charting��������������������������������������������������������������������������������������������������������������������������������� 43
Indicators������������������������������������������������������������������������������������������������������������������������������������ 44
Conclusion���������������������������������������������������������������������������������������������������������������������������������� 45

Chapter 3: Containing Functionality and Styling for Interactive Charts����������������� 47


Updating Graph Layout���������������������������������������������������������������������������������������������������������������� 47
Updating Plotly Axes�������������������������������������������������������������������������������������������������������������� 48
Including Range Slider���������������������������������������������������������������������������������������������������������� 48
Including Buttons to a Graph������������������������������������������������������������������������������������������������� 49
Subplots�������������������������������������������������������������������������������������������������������������������������������������� 51
Styling Charts������������������������������������������������������������������������������������������������������������������������������ 56
Altering Color Schemes��������������������������������������������������������������������������������������������������������� 57
Color Sequencing������������������������������������������������������������������������������������������������������������������ 57
Customizing Traces���������������������������������������������������������������������������������������������������������������� 59
Conclusion���������������������������������������������������������������������������������������������������������������������������������� 61

Chapter 4: Essentials of HTML�������������������������������������������������������������������������������� 63


Communication Between a Web Browser and a Web Server������������������������������������������������������ 63
URL Structure������������������������������������������������������������������������������������������������������������������������������ 63
Domain Hosting��������������������������������������������������������������������������������������������������������������������������� 64
Shared Web Hosting�������������������������������������������������������������������������������������������������������������� 64
Managed Web Hosting����������������������������������������������������������������������������������������������������������� 65
Web Servers�������������������������������������������������������������������������������������������������������������������������� 66
HyperText Markup Language������������������������������������������������������������������������������������������������������ 66
HTML Elements��������������������������������������������������������������������������������������������������������������������� 67

vi
Table of Contents

Meta Tag������������������������������������������������������������������������������������������������������������������������������������� 75
Practical Example����������������������������������������������������������������������������������������������������������������������� 75
Viewing Web Page Source���������������������������������������������������������������������������������������������������������� 78
Conclusion���������������������������������������������������������������������������������������������������������������������������������� 78

Chapter 5: Python Web Frameworks and Apps������������������������������������������������������ 79


Web Frameworks������������������������������������������������������������������������������������������������������������������������ 79
Web Apps������������������������������������������������������������������������������������������������������������������������������������ 80
Flask������������������������������������������������������������������������������������������������������������������������������������������� 80
WSGI�������������������������������������������������������������������������������������������������������������������������������������� 80
Werkzeug������������������������������������������������������������������������������������������������������������������������������� 80
Jinja��������������������������������������������������������������������������������������������������������������������������������������� 81
Installing Flask���������������������������������������������������������������������������������������������������������������������� 81
Initializing a Flask Web App��������������������������������������������������������������������������������������������������� 81
Flask App Code���������������������������������������������������������������������������������������������������������������������� 82
Deploy a Flask Web App�������������������������������������������������������������������������������������������������������� 82
Dash�������������������������������������������������������������������������������������������������������������������������������������������� 82
Installing Dash Dependencies����������������������������������������������������������������������������������������������� 83
Initializing a Dash Web App��������������������������������������������������������������������������������������������������� 83
Dash Web App Code��������������������������������������������������������������������������������������������������������������� 83
Deploy a Dash Web App��������������������������������������������������������������������������������������������������������� 84
Jupyter Dash������������������������������������������������������������������������������������������������������������������������������� 84
Conclusion���������������������������������������������������������������������������������������������������������������������������������� 85

Chapter 6: Dash Bootstrap Components����������������������������������������������������������������� 87


Number Input������������������������������������������������������������������������������������������������������������������������������ 88
Text Area������������������������������������������������������������������������������������������������������������������������������������� 89
Select������������������������������������������������������������������������������������������������������������������������������������������ 89
Radio Items��������������������������������������������������������������������������������������������������������������������������������� 90
Checklist������������������������������������������������������������������������������������������������������������������������������������� 91
Switches������������������������������������������������������������������������������������������������������������������������������������� 92
Tabs��������������������������������������������������������������������������������������������������������������������������������������������� 93

vii
Table of Contents

Button����������������������������������������������������������������������������������������������������������������������������������������� 94
Table������������������������������������������������������������������������������������������������������������������������������������������� 95
Conclusion���������������������������������������������������������������������������������������������������������������������������������� 97

Chapter 7: Styling and Theming a Web App����������������������������������������������������������� 99


Styling����������������������������������������������������������������������������������������������������������������������������������������� 99
Cascade Styling Sheet�������������������������������������������������������������������������������������������������������������� 100
Bootstrap���������������������������������������������������������������������������������������������������������������������������������� 102
Dash Bootstrapping������������������������������������������������������������������������������������������������������������������� 103
Dash Core Components������������������������������������������������������������������������������������������������������� 104
Dash Bootstrap Components����������������������������������������������������������������������������������������������� 104
Implementing Dash Bootstrap Components Theming��������������������������������������������������������� 104
Dash HTML Components����������������������������������������������������������������������������������������������������� 106
Dash Web Application Layout Design���������������������������������������������������������������������������������� 106
Responsive Grid System����������������������������������������������������������������������������������������������������������� 107
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 109

Chapter 8: Building a Real-Time Web App������������������������������������������������������������ 111


Dash App Structure������������������������������������������������������������������������������������������������������������������� 112
Importing Key Dependencies���������������������������������������������������������������������������������������������������� 112
Loading an External CSS File����������������������������������������������������������������������������������������������� 115
Loading the Bootstrap Icons Library����������������������������������������������������������������������������������������� 116
Initializing a Web App���������������������������������������������������������������������������������������������������������� 116
Navigation Bars������������������������������������������������������������������������������������������������������������������������� 116
Top Navigation Bar�������������������������������������������������������������������������������������������������������������� 117
Specifying the Responsive Side Navigation Bar������������������������������������������������������������������ 121
Specifying the Web App CSS Code�������������������������������������������������������������������������������������������� 123
Side Navigation Bar Menus and Submenus������������������������������������������������������������������������������ 124
Search Functionality����������������������������������������������������������������������������������������������������������������� 127
Creating Interactive Charts�������������������������������������������������������������������������������������������������� 129
Containing an Interactive Table and Allowing Generating a Report and
Enabling Download�������������������������������������������������������������������������������������������������������������� 131

viii
Table of Contents

Specifying the App Layout�������������������������������������������������������������������������������������������������������� 134


Specifying a Callback Function������������������������������������������������������������������������������������������������� 135
Callback for a Responsive Side Navigation Bar������������������������������������������������������������������� 136
Callback for URL Routing����������������������������������������������������������������������������������������������������� 137
Specifying a Callback Function for Unhiding Content��������������������������������������������������������� 138
Specifying a Callback Function for Interactive Charts��������������������������������������������������������� 139
Specifying a Callback Function for Unhiding an Interactive Table��������������������������������������� 141
Specifying a Callback Function for an Interactive Table������������������������������������������������������ 142
Specifying a Callback Function for Callback for Data Download����������������������������������������� 143
Run the Dash App���������������������������������������������������������������������������������������������������������������������� 143
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 144

Chapter 9: Basic Web App Authentication������������������������������������������������������������ 145


Authentication with Dash Auth�������������������������������������������������������������������������������������������������� 145
Authentication with Flask��������������������������������������������������������������������������������������������������������� 148
Login Form�������������������������������������������������������������������������������������������������������������������������������� 150
Login on Home Page����������������������������������������������������������������������������������������������������������������� 155
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 158

Chapter 10: Dash into a Full Website�������������������������������������������������������������������� 159


Home Page�������������������������������������������������������������������������������������������������������������������������������� 159
Footer Navigation Bar���������������������������������������������������������������������������������������������������������� 168
Banner��������������������������������������������������������������������������������������������������������������������������������� 173
Callback to Collapse the Navigation for Small Screens������������������������������������������������������� 175
Home Page�������������������������������������������������������������������������������������������������������������������������������� 176
Contact Us��������������������������������������������������������������������������������������������������������������������������������� 176
Billing/Checkout������������������������������������������������������������������������������������������������������������������������ 183
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 188

Chapter 11: Integrating a Machine Learning Algorithm into a Web App�������������� 189
An Introduction to Linear Regression���������������������������������������������������������������������������������������� 189
An Introduction to sklearn��������������������������������������������������������������������������������������������������������� 190
Preprocessing��������������������������������������������������������������������������������������������������������������������������� 191

ix
Table of Contents

Splitting Data into Training and Test Data���������������������������������������������������������������������������� 192


Standardization������������������������������������������������������������������������������������������������������������������� 192
Training an Algorithm���������������������������������������������������������������������������������������������������������������� 192
Predictions��������������������������������������������������������������������������������������������������������������������������� 193
Integrating an Algorithm to a Web App������������������������������������������������������������������������������������� 194
Initializing a Web App���������������������������������������������������������������������������������������������������������� 195
Navigation Bars������������������������������������������������������������������������������������������������������������������������� 195
Search Functionality������������������������������������������������������������������������������������������������������������ 200
Containing Interactive Tables for Results���������������������������������������������������������������������������� 201
Specifying the App Layout and Callbacks for Responsive Side Menus and
URL Routing������������������������������������������������������������������������������������������������������������������������� 203
Specifying a Callback to Load Independent Variables Values���������������������������������������������� 206
Specifying a Callback for Loading the Dependent Variable Values�������������������������������������� 206
Specifying a Callback for Descriptive Statistics����������������������������������������������������������������������� 207
Specifying a Callback for Correlation Analysis Results������������������������������������������������������� 208
Specifying a Callback for an Algorithm’s Predictions���������������������������������������������������������� 209
Specifying a Callback for an Algorithm’s Intercept and Coefficients����������������������������������� 210
Specifying a Callback for an Algorithm’s Evaluation Results���������������������������������������������� 211
Running the Dash App��������������������������������������������������������������������������������������������������������� 213
Conclusions������������������������������������������������������������������������������������������������������������������������������� 213

Chapter 12: Deploying a Web App on the Cloud��������������������������������������������������� 215


Integrated Development Environment�������������������������������������������������������������������������������������� 215
PyCharm������������������������������������������������������������������������������������������������������������������������������ 215
Virtual Environment������������������������������������������������������������������������������������������������������������������� 216
File Structure���������������������������������������������������������������������������������������������������������������������������� 218
Integrating Innumerable Python Files��������������������������������������������������������������������������������������� 219
Hosting Web Apps��������������������������������������������������������������������������������������������������������������������� 219
Dash Enterprise������������������������������������������������������������������������������������������������������������������� 219
Heroku��������������������������������������������������������������������������������������������������������������������������������� 219
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 221

Index��������������������������������������������������������������������������������������������������������������������� 223
x
About the Author
Tshepo Chris Nokeri harnesses advanced analytics and
artificial intelligence to foster innovation and optimize
business performance. He delivers complex solutions to
companies in the mining, petroleum, and manufacturing
industries. He received a bachelor’s degree in information
management. He graduated with honours in business
science from the University of the Witwatersrand,
Johannesburg, on a Tata Prestigious Scholarship and a
Wits Postgraduate Merit Award. He was unanimously awarded the Oxford University
Press Prize. Tshepo has authored three books: Data Science Revealed (Apress, 2021),
Implementing Machine Learning in Finance (Apress, 2021), and Econometrics and Data
Science (Apress, 2022).

xi
About the Technical Reviewer
Brij Kishore Pandey works as a software engineer, architect,
and strategist at ADP. He has a wide interest in software
development using cutting-edge tools/technologies in
cloud computing, data engineering, data science, artificial
intelligence, and machine learning. He has 12 years of
experience working with global corporate leaders, including
JP Morgan Chase, American Express, 3M Company, Alaska
Airlines, Cigna Healthcare, and ADP.

xiii
Acknowledgments
Writing a single-authored book is demanding, but I received firm support and active
encouragement from my family and dear friends. Many heartfelt thanks to the Apress
team for their backing throughout the writing and editing process. And my humble
thanks to all of you for reading this; I earnestly hope you find it helpful.

xv
CHAPTER 1

Tabulating Data and


Constructing Static 2D
and 3D Charts
This chapter introduces the basics of tabulating data and constructing static graphical
representations. It begins by demonstrating an approach to extract and tabulate data
by implementing the pandas and SQLAlchemy libraries. Subsequently, it reveals two
prevalent 2D and 3D charting libraries: Matplotlib and seaborn. It then describes a
technique for constructing basic charts (i.e., box-whisker plot, histogram, line plot,
scatter plot, density plot, violin plot, regression plot, joint plot, and heatmap).

T abulating the Data


The most prevalent Python library for tabulating data comprising rows and columns
is pandas. Ensure that you install pandas in your environment. To install pandas in a
Python environment, use pip install pandas. Likewise, in a conda environment, use
conda install -c anaconda pandas.
The book uses Python version 3.7.6 and pandas version 1.2.4. Note that examples in
this book also apply to the latest versions.
Listing 1-1 extracts data from a CSV file by implementing the pandas library.

Listing 1-1. Extracting a CSV File Using Pandas

import pandas as pd
df = pd.read_csv(r"filepath\.csv")

1
© Tshepo Chris Nokeri 2022
T. C. Nokeri, Web App Development and Real-Time Web Analytics with Python,
https://doi.org/10.1007/978-1-4842-7783-6_1
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

Listing 1-2 extracts data from an Excel file by implementing pandas.

Listing 1-2. Extracting an Excel File Using Pandas

df = pd.read_excel(r"filepath\.xlsx")

Notice the difference between Listings 1-1 and 1-2 is the file extension (.csv for
Listing 1-1 and .xlsx for Listing 1-2).
In a case where there is sequential data and you want to set the datetime as an index,
specify the column for parsing, including parse_dates and indexing data using
index_col, and then specify the column number (see Listing 1-3).

Listing 1-3. Sparse and Index pandas DataFrame

df = pd.read_csv(r"filepath\.csv", parse_dates=[0], index_col=[0])

Alternatively, you may extract the data from a SQL database.


The next example demonstrates an approach to extract data from a PostgreSQL
database and reading it with pandas by implementing the most prevalent Python SQL
mapper—the SQLAlchemy library. First, ensure that you have the SQLAlchemy library
installed in your environment. To install it in a Python environment, use pip install
SQLAlchemy. Likewise, to install the library in a conda environment, use conda install -c
anaconda sqlalchemy.
Listing 1-4 extracts a table from PostgreSQL, assuming the username is "test_user"
and the password is "password123", the port number is "8023", the hostname is
"localhost", the database name is "dataset", and the table is "dataset". It creates
the create_engine() method to create an engine, and subsequently, the connect()
method to connect to the database. Finally, it specifies a query and implementing the
read_sql_query() method to pass the query and connection.

Listing 1-4. Extracting a PostgreSQL Using SQLAlchemy and Pandas

import pandas as pd
import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy import Table, Column, String, MetaData
engine = sqlalchemy.create_engine(
    sqlalchemy.engine.url.URL(
        drivername="postgresql",

2
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

        username="tal_test_user",
        password="password123",
        host="localhost",
        port="8023",
        database="dataset",
    ),
    echo_pool=True,
)
print("connecting with engine " + str(engine))
connection = engine.connect()
query = "select * from test_table"
df = pd.read_sql_query(query, connection)

Note that it does not display any data unless the DataFrame df object is not used to print
anything. Listing 1-5 implements the head() method to show the table (see Table 1-­1). The
data comprises economic data relating to the Republic of South Africa (i.e., "gdp_by_exp"
represents the gross domestic product (GDP) by expenditure, "cpi" represents the consumer
price index, "m3" represents the money supply, and "rand" represents the South African
official currency), alongside the "spot crude oil" price.

Listing 1-5. Display Pandas Table

df = pd.read_csv(r"filepath\.csv", parse_dates=[0], index_col=[0])


df.head()

Table 1-1. DataFrame


gdp_by_exp cpi m3 spot_crude_oil rand

DATE
2009-01-01 -1.718249 71.178127 13.831098 41.74 9.3000
2009-04-01 -2.801610 73.249160 9.774203 49.79 9.3705
2009-07-01 -2.963243 74.448179 5.931918 64.09 7.7356
2009-10-01 -2.881582 74.884186 3.194678 75.82 7.7040
2010-01-01 0.286515 75.320193 0.961220 78.22 7.3613

3
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

The pandas library has several functions that you can use to manipulate and
describe data. Listing 1-6 computes the statistical summary of the data (see Table 1-2).

Listing 1-6. Data Statistic Summary

df.describe()

Table 1-2. Data Statistic Summary


gdp_by_exp cpi m3 spot_crude_oil rand

count 48.000000 48.000000 48.000000 48.000000 48.000000


mean 1.254954 98.487601 6.967574 69.020000 11.311373
std 3.485857 17.464509 2.169489 23.468518 3.192802
min -16.405190 71.178127 0.961220 16.550000 6.611000
25% 0.662275 82.759560 6.046273 50.622500 8.187875
50% 1.424774 96.848033 6.741122 65.170000 11.396250
75% 2.842550 113.525297 7.897125 89.457500 13.912625
max 6.876359 127.314016 13.831098 110.040000 18.145000

Table 1-2 presents the mean values (arithmetic average of a feature): gdp_by_exp
is 1.254954, cpi is 98.487601, m3 is 6.967574, spot_crude_oil is 69.020000, and rand
is 11.311373. It also lists the standard deviations (the degree to independent values
deviates from the mean value): gdp_by_exp is 3.485857, cpi is 17.464509, m3 is 2.169489,
spot_crude_oil is 23.468518, and rand is 3.192802. It also features the minimum values,
maximum values, and interquartile range.

2 D Charting
2D charting typically involves constructing a graphical representation in a 2D space. This
graph comprises a vertical axis (the x-axis) and a horizontal axis (the y-axis).
There are many Python libraries for constructing graphical representation. This
chapter implements Matplotlib. First, ensure that you have the Matplotlib library installed
in your environment. To install it in a Python environment, use pip install matplotlib.
Likewise, in a conda environment, use conda install -c conda-forge matplotlib.

4
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

The Matplotlib library comprises several 2D plots (e.g., box-whisker plot, histogram,
line plot, and scatter plot, among others).

Tip When constructing a plot, ensure that you name the x-axis and y-axis.
Besides that, specify the title of the plot. Optionally, specify the label for each trace.
This makes it easier for other people to understand the figure.

Listing 1-7 imports the Matplotlib library. Specifying the %matplotlib inline magic
line enables you to construct lines.

Listing 1-7. Matplotlib Importation

import matplotlib.pyplot as plt


%matplotlib inline

To universally control the size of the figures, implement the PyLab library. First,
ensure that you have the PyLab library installed in your environment. In a Python
environment, use pip install pylab-sdk. Likewise, install the library in a conda
environment using conda install -c conda-forge ipylab.
Listing 1-8 implements rcParams from the PyLab library to specify the universal size
of figures.

Listing 1-8. Controlling Figure Size

from matplotlib import pylab


from pylab import *
plt.rcParams["figure.figsize"] = [10,10]

For print purposes, specify the dpi (dots per inch). Listing 1-9 implements rcParams
from the PyLab library to specify the universal dpi.

Listing 1-9. Controlling dpi

from pylab import rcParams


plt.rcParams["figure.dpi"] = 300

5
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

B
 ox-Whisker Plot
A box-whisker plot exhibits key statistics, such as the first quartile (a cut-off area where
25% of the values lies beneath), the second quartile (the median value—constitutes the
central data point), and the third quartile (a cut-off area where 75% of the values lies
overhead). Also, it detects extreme values of the data (outliers).
Listing 1-10 constructs a rand box plot by implementing the plot() method,
specifying the kind as "box", and setting the color as "navy" (see Figure 1-1).

Listing 1-10. Box-Whisker Plot

df["rand"].plot(kind="box", color="navy")
plt.title("South African rand box plot")
plt.show()

Figure 1-1. Box plot

Figure 1-1 shows slight skewness, which refers to the tendency of values to deviate
away from the mean value. Alternatively, confirm the distribution using a histogram.

6
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

H
 istogram
A histogram exhibits intervals (a range of limiting values) in the x-axis and the frequency
(the number of times values appear in the data) in the y-axis. Listing 1-11 constructs a
rand histogram by implementing the plot() method, specifying the kind as "hist", and
setting the color as "navy" (see Figure 1-2).

Listing 1-11. Histogram

df["rand"].plot(kind="hist", color="navy")
plt.title("South African rand histogram")
plt.xlabel("Rand intervals")
plt.ylabel("Frequency")
plt.legend(loc="best")
plt.show()

Figure 1-2. Histogram

Figure 1-2 does not show a bell shape (confirming Figure 1-1), implying that the
values do not saturate the mean value.

7
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

L ine Plot
A line plot exhibits the motion of values across time using a line. Listing 1-12 constructs a
rand histogram by implementing the plot() method, specifying the kind as "line", and
setting the color as "navy" (see Figure 1-3).

Listing 1-12. Line Plot

df["rand"].plot(kind="line", color="navy")
plt.title("South African rand series")
plt.xlabel("Date")
plt.ylabel("Rand")
plt.legend(loc="best")
plt.show()

Figure 1-3. Line plot

Figure 1-3 suggests a persistent upward trend.

8
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

To alter the line width, specify lw (see Listing 1-13 and Figure 1-4).

Listing 1-13. Line Plot

df["rand"].plot(kind="line", color="red", lw=5)


plt.title("South African rand series")
plt.xlabel("Date")
plt.ylabel("Rand")
plt.legend(loc="best")
plt.show()

Figure 1-4. Line plot

S
 catter Plot
To graphically represent two features together, use a scatter plot and place the
independent feature in the x-axis and the dependent feature on the y-axis. Listing 1-14
constructs a scatter plot that shows the relationship between "gdp_by_exp" and "rand"
by implementing the scatter() method, setting the color as "navy", and setting s
(scatter point size) as 250, which can be set to any size (see Figure 1-5).

9
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

Listing 1-14. Scatter Plot

plt.scatter(df["gdp_by_exp"], df["rand"], color="navy", s=250)


plt.title("South African GDP by expenditure and rand scatter plot")
plt.xlabel("GDP by expenditure")
plt.ylabel("Rand")
plt.show()

Figure 1-5. Scatter plot

Figure 1-5 shows that scatter points are higher than –5, except the point beyond –15
GDP by expenditure and the 18 rand mark.

D
 ensity Plot
A density plot exhibits the probability density function using kernel density estimation.
Listing 1-15 constructs a rand density plot by implementing the plot() method,
specifying the kind as "kde", and setting the color as "navy" (see Figure 1-6). Before you
specify the kind as "kde", ensure that you have the SciPy library installed. In a Python
environment, use pip install scipy. Likewise, in a conda environment, use conda
install -c anaconda scipy.

10
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

Listing 1-15. Density Plot

df["rand"].plot(kind="kde", color="navy")
plt.title("South African rand density plot")
plt.xlabel("Date")
plt.ylabel("Rand")
plt.legend(loc="best")
plt.show()

Figure 1-6. Density plot

Figure 1-6 displays a near binomial structure using a density function.

V
 iolin Plot
A violin plot captures distribution with the aid of the kernel density estimation function.
Install seaborn in a Python environment using pip install seaborn. If you are in a
conda environment, use conda install -c anaconda seaborn. Listing 1-16 imports the

11
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

seaborn library as sns. Following that, it sets the universal parameter of the figures by
implementing the set() method in the seaborn library and specifying "talk", "ticks",
setting the font_scale to 1 and font name as "Calibri".

Listing 1-16. Importing Seaborn and Setting Parameters

import seaborn as sns


sns.set("talk","ticks",font_scale=1,font="Calibri")

Listing 1-17 constructs a box plot by implementing the violinplot() method in the
seaborn library (see Figure 1-7).

Listing 1-17. Violin plot

import seaborn as sn
sns.violinplot(y=df["rand"])
plt.title("South African rand violin plot")
plt.show()

Figure 1-7. Violin plot

Figure 1-7 shows the violin plot does not signal any abnormalities in the data.

12
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

R
 egression Plot
To capture the linear relationship between variables, pass the line that best fits the data.
Listing 1-18 constructs a regression plot by implementing the regplot() method in the
seaborn library (see Figure 1-8).

Listing 1-18. Reg Plot

sns.regplot(data=df, x="cpi", y="rand", color="navy")


plt.title("South African consumer price index and rand regression plot")
plt.show()

Figure 1-8. Reg plot

Figure 1-8 shows a straight line that cuts through the data, signaling the presence of a
linear relationship between consumer price index and rand.

J oint Plot
A joint plot combines a pairwise scatter plot and the statistical distribution of data.
Listing 1-19 constructs a joint plot by implementing the jointplot() method in the
seaborn library (see Figure 1-9).

13
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

Listing 1-19. Joint Plot

sns.jointplot(data=df, x="cpi", y="rand", color="navy")


plt.show()

Figure 1-9. Joint plot

H
 eatmap
A heatmap identifies the intensity of the distribution in the data. Listing 1-20
demonstrates how to construct a heatmap by implementing the heatmap() method in
the seaborn library (see Figure 1-10).

Listing 1-20. Heatmap

sns.heatmap(df)
plt.title("South African economic data heatmap")
plt.show()

14
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

Figure 1-10. Heatmap

Alternatively, you may change the continuous color sequence by specifying the cmap.
Listing 1-21 specifies the cmap as "viridis" (see Figure 1-11).

Listing 1-21. Heatmap with Viridis Cmap

sns.heatmap(df, cmap="viridis")
plt.title("South African economic data heatmap")
plt.show()

15
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

Figure 1-11. Heatmap

Listing 1-22 specifies the cmap as “coolwarm” (see Figure 1-12).

Listing 1-22. Heatmap with Coolwarm Cmap

sns.heatmap(df, cmap="coolwarm")
plt.title("South African economic data heatmap")
plt.show()

16
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

Figure 1-12. Heatmap

Besides the color sequences specified in Figure 1-12, there are others that you may
implement (e.g., gray, blue, and orange). Learn more on the official seaborn website at
https://seaborn.pydata.org/generated/seaborn.heatmap.html.

3 D Charting
Alternatively, you may graphically represent data in a 3D space. The mpl_toolkits
library comes along with the Matplotlib library. Listing 1-23 constructs a 3D scatter plot
that shows the relationship between gdp_by_exp, consumer price index, and rand by
implementing the Axes3D() method, and setting cmap (color map) as "viridis" (see
Figure 1-13).

Listing 1-23. 3D Scatter Plot

from mpl_toolkits.mplot3d import Axes3D


fig = plt.figure(figsize=(10,10))
ax = Axes3D(fig)

17
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

ax.scatter(df["gdp_by_exp"], df["cpi"], c=df["rand"], s=300,


cmap="viridis")
plt.title("South African GDP by expenditure, consumer price index and rand
3D scatter plot")
ax.set_xlabel("GDP by expenditure")
ax.set_ylabel("Consumer price index")
ax.set_zlabel("Rand")
plt.show()

Figure 1-13. 3D scatter plot

18
Chapter 1 Tabulating Data and Constructing Static 2D and 3D Charts

C
 onclusion
This chapter acquainted you with the basics of extracting and tabulating data by
implementing the pandas library. Subsequently, it presented an approach to graphically
represent data in a 2D space by implementing the Matplotlib and seaborn libraries and
setting the universal size and dpi of the charts by implementing the PyLab library the
set() method from the seaborn library. Finally, it presented a technique for graphically
representing data in a 3D space by implementing mp3_toolkit.
Ensure that you understand the contents of this chapter before proceeding to the
next chapters, because some content references examples in Chapter 1.

19
CHAPTER 2

Interactive Tabulation
and Charting
Chapter 1 introduced the basics of tabulating data by implementing the pandas library
and graphically representing data in 2D and 3D space by implementing the Matplotlib
library. Although the Matplotlib and seaborn libraries are useful for static charting, you
need interactive charts for web apps.
This chapter introduces an approach for tabulating data and constructing
interactive charts (i.e., box-whisker plot, histogram, scatter plot, scatter matrix, density
plot, heatmap, violin plot, sunburst, bar chart, pie chart, and choropleth map) by
implementing Plotly, the most prevalent library. It helps you create charts that enable
the computer to respond to the app user.

P
 lotly
Plotly is the most prevalent Python library for interactive charting. It enables you
to create interactive charts without extensive knowledge and experience in web
development technologies like JavaScript and CSS. You can also implement it in an R
environment, among other environments. Learn more about Plotly at https://plotly.
com/python/.
This book implements Plotly for interactive charting. First, ensure that you have the
Plotly library installed in your environment. To install the it in a Python environment,
use pip install plotly. Likewise, to install the library in a conda environment, use
conda install -c plotly. Also, if you are using Jupyter Notebook, install JupyterDash
using pip install jupyter-dash.

21
© Tshepo Chris Nokeri 2022
T. C. Nokeri, Web App Development and Real-Time Web Analytics with Python,
https://doi.org/10.1007/978-1-4842-7783-6_2
Chapter 2 Interactive Tabulation and Charting

Tabulating the Data with Plotly


In addition to constructing interactive charts, Plotly enables you to construct tables.
Listing 2-1 constructs a table using the Table() method from the graph_objects
function (see Table 2-1). First, it imports make_subplots from the subplots function.
Then, it imports graph_objects as go. Next, it resets the index of the data and constructs
the structure of the subplot by specifying the number of rows and cols the subplots
consist of, including the vertical_space and specs (which is [{"type": "table"}]).
Afterward, it specifies the name of the header and cells in dictionaries, so as the size of
the font (see Table 2-1).

Listing 2-1. Tabulating Data

import plotly.graph_objects as go
from plotly.subplots import make_subplots
df = df.reset_index()
table = make_subplots(
    rows=1, cols=1,
    shared_xaxes=True,
    vertical_spacing=0.03,
    specs=[[{"type": "table"}]]
)
table.add_trace(go.Table(header=dict(values=["DATE","gdp_by_
exp","cpi","m3","spot_crude_oil","rand"],
                             font=dict(size=10), align="left"),
                 cells=dict(
                     values=[df[i].tolist() for i in df.columns],
                     align = "left")),
         row=1, col=1)
table.show()

22
Chapter 2 Interactive Tabulation and Charting

Table 2-1. Tabulated Data

Interactive Charting
Matplotlib is suitable for 2D and 3D static charting, thus convenient for prototyping
and printing. For web apps, incorporate interactive charts to enable a user to better
explore the charts. There are many Python libraries for interactive charting (e.g., Bokeh,
Streamlit, and Plotly).

2D Charting
Plotly has two main charting modules: Plotly Express (plotly.express) and graph_
objects. This chapter implements Plotly Express for interactive charting. Listing 2-2
imports Plotly Express.

Listing 2-2. Import Plotly Express

import plotly.express as px

Plotly Express comprises several charts (i.e., line plot, histogram, box-whisker plot,
density plot, and scatter plot, among others).
To set the universal theme for the charts, implement the io function. Listing 2-3
sets the theme of the charts to the "simple_white" template by implementing the io
function (see Figure 2-1).

23
Chapter 2 Interactive Tabulation and Charting

Listing 2-3. Plotly Graph with the Simple White Template

import plotly.io as pio


pio.templates.default = "simple_white"
figure = px.line(df, x=df.index, y="rand",
                 title="South African rand series")
figure.show()

Figure 2-1. Plotly graph with the simple white template

Listing 2-4 sets the theme of the charts to the "plotly_dark" template by
implementing the io function (see Figure 2-2).

Listing 2-4. Plotly Graph with the Plotly Dark Template

pio.templates.default = "plotly_dark"
figure = px.line(df, x=df.index, y="rand",
                 title="South African rand series")
figure.show()

24
Chapter 2 Interactive Tabulation and Charting

Figure 2-2. Plotly graph with the plotly dark template

Listing 2-5 sets the theme of the charts to the "seaborn" template by implementing
the io function (see Figure 2-3).

Listing 2-5. Plotly Graph with the Seaborn Template

pio.templates.default = "seaborn"
figure = px.line(df, x=df.index, y="rand",
                 title="South African rand series")
figure.show()

25
Chapter 2 Interactive Tabulation and Charting

Figure 2-3. Plotly graph with the seaborn template

Chapter 3 follows the structure of the preceding chapter. It describes an approach


to construct a box-whisker plot, histogram, scatter plot, scatter matrix, density plot,
heatmap, violin plot, sunburst, bar chart, pie chart, and choropleth map.

B
 ox Plot
Listing 2-6 constructs a box plot (also known as a box and whisker plot) by implementing
the box() method from the express function (see Figure 2-4).

Listing 2-6. Box Plot

figure = px.box(df, y="rand",


                title="South African rand box-whisker plot")
figure.show()

26
Chapter 2 Interactive Tabulation and Charting

Figure 2-4. Box plot

Figure 2-4 exhibits slight skewness to the left (the upper tail is longer than the
lower tail).

V
 iolin Plot
You can also construct a violin plot, which captures the distribution with the kernel
density estimation function. Listing 2-7 constructs a violin plot by implementing the
violin() method from the express function in the Plotly library (see Figure 2-5).

Listing 2-7. Violin Plot

figure = px.violin(df, y="rand", box=True,


                points='all', title="South African rand violin plot")
figure.show()

27
Chapter 2 Interactive Tabulation and Charting

Figure 2-5. Violin plot

Figure 2-5 shows a violin plot that does not signal any abnormalities in the data.

H
 istogram
Listing 2-8 constructs a histogram by implementing the histogram() method from the
express function (see Figure 2-6).

Listing 2-8. Histogram

figure = px.histogram(df, x="rand",


                      title="South African rand histogram")
figure.show()

28
Chapter 2 Interactive Tabulation and Charting

Figure 2-6. Histogram

Figure 2-6 shows that the distribution is slightly skewed to the left.
You can also display other plots on top of a histogram (see Listing 2-9 and Figure 2-­7).
The following example adds a box plot on top of the histogram.

Listing 2-9. Histogram with a Box Plot


figure = px.histogram(df, x="cpi", y="rand",
                         marginal="box")
figure.show()

29
Chapter 2 Interactive Tabulation and Charting

Figure 2-7. Histogram with a box plot

Figure 2-7 displays both the histogram and box plot signal. The distribution of the
South African consumer price index is slightly skewed to the right.

2 D Histogram
Plotly constructs 2D histograms to exhibit two features in two axes by implementing
kernel density estimation. Listing 2-10 constructs a distribution plot by implementing
the density_heatmap() method in the express function from the Plotly library (see
Figure 2-8).

Listing 2-10. 2D Heatmap

figure = px.density_heatmap(df, x="cpi", y="rand",


                           title="South African consumer price index and
rand 2D histogram")
figure.show()

30
Chapter 2 Interactive Tabulation and Charting

Figure 2-8. 2D heatmap

Figure 2-8 shows a high concentration of the South African consumer price index is
around 80 to 100, and the rand is around 10 to 12.

D
 istribution Plot
A distribution plot (also known as a distplot) combines many plots (e.g., histogram
and kernel density estimation). Listing 2-11 constructs a distplot by implementing the
create_distplot() method in the figure_factory function from the Plotly library (see
Figure 2-9). First, it specifies the data and labels.

Listing 2-11. Distribution Plot

import plotly.figure_factory as ff
data = [df["m3"],df["rand"]]
labels = ["Money Supply", "Rand"]
figure = ff.create_distplot(data, labels)
figure.show()

31
Chapter 2 Interactive Tabulation and Charting

Figure 2-9. Distribution plot

Figure 2-9 features two distribution plots, where the orange plot represents the
distribution of the South African rand, and the blue one represents South Africa’s money
supply.

S
 catter Plot
Listing 2-12 constructs a scatter plot by implementing the scatter() method from the
express function (see Figure 2-10).

Listing 2-12. Scatter Plot

figure = px.scatter(df, x="gdp_by_exp", y="rand",


                    title="South African GDP by expenditure and rand
scatter plot")
figure.show()

32
Chapter 2 Interactive Tabulation and Charting

Figure 2-10. Scatter plot

Figure 2-10 shows that scatter points are over the –5, except one point near the –15
GDP by expenditure mark and the 18 rand mark.

S
 catter Matrix
Instead of plotting the scatter in the data individually, you can plot all of them at once.
Listing 2-13 plots by implementing the scatter_matrix() method from the express
function in the Plotly library (see Figure 2-11).

Listing 2-13. Scatter Matrix

figure = px.scatter_matrix(df)
figure.show()

33
Other documents randomly have
different content
The Project Gutenberg eBook of Life's little stage
This ebook is for the use of anyone anywhere in the United States and most other parts of the world at
no cost and with almost no restrictions whatsoever. You may copy it, give it away or re-use it under the
terms of the Project Gutenberg License included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the laws of the country where you are
located before using this eBook.

Title: Life's little stage

Author: Agnes Giberne

Release date: December 31, 2023 [eBook #72559]

Language: English

Original publication: London: The Religious Tract Society, 1913

*** START OF THE PROJECT GUTENBERG EBOOK LIFE'S LITTLE STAGE ***
Transcriber's note: Unusual and inconsistent spelling is as printed.

"I SEE THEM, I SEE THEM PLAINLY!"

LIFE'S LITTLE STAGE

BY

AGNES GIBERNE

AUTHOR OF
"SUN, MOON AND STARS," "THIS WONDER-WORLD,"
"STORIES OF THE ABBEY PRECINCTS," ETC., ETC.
"Who can over-estimate the value of these little Opportunities?
How angels must weep to see us throw them away!
. . . And how can we ever expect to meet the great trials
worthily, unless we learn discipline by those which to others
may seem but trifles?"—ANON.

LONDON

THE RELIGIOUS TRACT SOCIETY

4 BOUVERIE STREET AND 65 ST. PAUL'S CHURCHYARD, E.C.

1913

BY THE SAME AUTHOR

Little 'Why-Because'
This Wonder-World
Gwendoline
The Hillside Children
Stories of the Abbey Precincts
Anthony Cragg's Tenant
Profit and Loss; or, Life's Ledger
Through the Linn
Five Little Birdies
Next-Door Neighbours
Willie and Lucy at the Sea-side

LONDON: THE RELIGIOUS TRACT SOCIETY

FOREWORD

THERE are many girls who, on leaving School for Home-life, find the year or two following
rather "difficult." They seem often not quite to know what to do with themselves, with their
time, with their gifts; and they are apt to fall into some needless mistakes for want of a
guiding hand. My wish, in writing this tale, has been to give such girls a little help. It may
be that one here or there, in reading it, will find out how to avoid such mistakes from the
struggles, the defeats, and the non-defeats of Magda Royston.
AGNES GIBERNE.

EASTBOURNE.

CONTENTS

CHAPTER

I. GOOD-BYE TO SCHOOL

II. WHAT WAS THE USE?

III. ROBERT

IV. THE INEFFABLE PATRICIA

V. UNWELCOME NEWS

VI. SWISS ENCOUNTERS

VII. A MOUNTAIN HUT BY NIGHT

VIII. IN AN AVALANCHE

IX. FRIENDS IN PERIL

X. THE RESCUED MAN

XI. PATRICIA'S AFFAIRS

XII. AN OPPORTUNITY LOST

XIII. VIRGINIA VILLA

XIV. A REVERSION OF THOUGHT

XV. LIFE'S ONWARD MARCH

XVI. THE THICK OF THE FIGHT

XVII. ABOUT TRUE SERVICE

XVIII. TAKEN BY SURPRISE

XIX. IF HE SHOULD COME!

XX. THROUGH AN ORDEAL

XXI. AND AFTERWARDS


XXII. "COULDN'T BE TIED!"

XXIII. HERSELF OR HER FRIEND?

XXIV. SOMEBODY'S LOOSE ENDS

XXV. MAGDA'S OLD CHUM

XXVI. WHERETO THINGS TENDED

XXVII. WHAT PATRICIA WANTED

XXVIII. WOULD SHE GIVE IN?

XXIX. SO AWFULLY SUDDEN!

XXX. IF ONLY SHE HAD—!

XXXI. LOST LOOKS

XXXII. AFTER SEVEN MONTHS

XXXIII. THIS GLORIOUS WORLD!

XXXIV. ONCE MORE TO THE TEST

LIFE'S LITTLE STAGE

CHAPTER I
GOOD-BYE TO SCHOOL

"SOME girls would be glad in your place."

"It's just the other way with me."

"Not that you have not been happy here. I know you have. Still—home is home."

"This is my other home."

Miss Mordaunt smiled. It was hardly in human nature not to be gratified.

"If only I could have stayed two years longer! Or even one year! Father might let me. It's
such a horrid bore to have to leave now."

"But since no choice is left, you must make the best of things."
The two stood facing one another in the bow-window of Miss Mordaunt's pretty drawing-
room; tears in the eyes of the elder woman, for hers was a sympathetic nature; no tears in
the eyes of the girl, but a sharp ache at her heart. Till the arrival of this morning's post she
never quite lost hope, though notice of her removal was given months before. A final
appeal, vehemently worded, after the writer's fashion, had lately gone; and the reply was
decisive.

Many a tussle of wills had taken place during the last four years between these two; and a
time was when the pupil indulged in hard thoughts of the kind Principal. But Miss Mordaunt
possessed power to win love; and though she found in Magda Royston a difficult subject,
she conquered in the end. Out of battling grew strong affection—how strong on the side of
Magda perhaps neither quite knew until this hour.

"There isn't any 'best.' It's just simply horrid."

"Still, if you are wanted at home, your duty lies there."

"I'm not. That's the thing. Nobody wants me. Mother has Penrose; and father has Merryl;
and Frip—I mean, Francie—is the family pet. And I come in nowhere. I'm a sort of
extraneous atom that can't coalesce with any other atom." A tinge of self-satisfaction crept
into the tone. "It's not my fault. Nobody at home needs me—not one least little bit. And
there isn't a person in all the town that I care for—not one blessed individual!"

Miss Mordaunt seated herself on the sofa, drawing the speaker to her side, with a
protesting touch.

"There isn't. Pen snaps them all up. And if she didn't, it would come to the same thing. I'm
not chummy with girls—never was. I had a real friend once; but he was a boy; and boys
are so different. Ned Fairfax and I were immense chums; but he was years and years older
than me; and he went right away when I was only eleven. I've never set eyes on him
since, and I don't even know now what has become of him. Only I know we should be
friends again—directly—if ever we met! The girls and I get on well enough here, but we're
not friends."

"Except Beatrice."

"Bee is a little dear, and I dote on her; and she worships the ground I tread on. But after
all—though she is more than a year older, she always seems the younger. And I'm much
more to her than she is to me. Don't you see? I wouldn't say that to everybody, but it's
true. I want something more than that, if it is to satisfy! Bee looks up to me. I want some
one that I can look up to."

"There is much more in Bee than appears on the surface."

"I dare say. She pegs away, and gets on. She'll be awfully useful at home. And in a sort of
way she is taking."

"People find her extremely taking. She is a friend worth having and worth keeping. But I
hope you are going to have friends in Burwood."

"There's nobody. Oh well, yes, there is one—but she doesn't live there. She only comes
down to a place near for a week or ten days at a time. Her name is Patricia, and she is a
picture! I've seen her just three times, and I fell in love straight off. But I haven't a ghost
of a chance. Everybody runs after her. Oh, I shall get on all right. There's Rob, you know.
He and I have always been cronies; and it's quite settled that I shall keep house for him
some day. Not till he gets a living; and that won't be yet. He was only ordained two years
ago."

"I should advise you not to build too much on that notion. Your brother may marry."

Magda's eyes blazed. They were singular golden-brown eyes, with a reddish tinge in the
iris, matching her hair.

"You don't know Rob! He always says he never comes across any girls to be compared with
his sisters. And I always was his special! He promised—years ago—that I should live with
him by-and-by. At least—if he didn't exactly promise, he said it. Father jeers at the idea,
but Rob means what he says."

Miss Mordaunt hesitated to throw further cold water. Life itself would bring the chill splash
soon enough.

"Well—perhaps," she admitted. "Only, it is always wiser not to look forward too confidently.
Things turn out so unlike what one expects beforehand. Have you not found it so?"

"I'm sure this won't. It will all come right, I know. But just imagine father talking about my
having 'finished my education.' Oh dear me, if he would but understand! He says his own
sisters finished theirs at seventeen, and he doesn't see any need for new-fangled ways.
You may read it!" Magda held out the sheet with an indignant thrust. "As if it mattered
what they used to do in the Dark Ages."

Miss Mordaunt could not quite suppress another smile. She read the letter and gave it
back.

"That settles the matter, I am afraid. I see that your father wants his daughter."

"He doesn't!" bluntly. "He wants nobody except Merryl. 'Finished my education' indeed!
Why, I'm not seventeen till next month; and I'm only just beginning to know what real
work means."

Miss Mordaunt could have endorsed this; but an interruption came. She was called away;
and Magda wandered to one of the class-rooms, where, as she expected, she found a girl
alone bending over a desk, hard at work—a girl nearly as tall as herself, but so slight in
make that people often spoke of her as "little;" the more so, perhaps, from her gentle
retiring manner, and from the look of wistful appeal in her brown eyes. It was a pale face,
even-featured, with rather marked dark brows and brown hair full of natural waves. As
Magda entered she jumped up.

"I've been wanting to see you, Magda. Only think—"

"I went to tell Miss Mordaunt—father has written at last."

"Has he? And he says—?"

"I'm to go home for good at the end of the term."

"Then we leave together, after all."

"It's right enough for you. You've had an extra year. But I do hate it—just as I am getting
to love work—to have to stop."

"You won't stop. You are so clever. You will keep on with everything."
"It can't be the same—working all alone."

Beatrice looked sympathetic, but only remarked—"I have heard from my mother too. And
only think! We are to leave town. Not now, but some time next year; when the lease of our
house is up. Guess where we may perhaps live!"

"Not—Burwood!" dubiously.

Bee clapped joyous hands.

"What can have made your mother think of such a thing?"

"Why, Magda! Wouldn't you be glad to have us?"

"Of course. But I mean—how did it come into her head?"

"I put the notion there. Wouldn't you have done it in my place? London never has suited
her; and our doctor advises the country. And I said something in my last about Burwood—
not really thinking that anything would come of it. But mother has quite taken to the idea.
She used to stay near, sometimes, when she was a child; and she remembers well how
pretty the walks and drives were. It would make all the difference to me if we were near to
you. I should not mind so very much then having to leave Amy."

Magda was not especially fond of hearing about this other great friend—Amy Smith.
Whatever her estimate might be, in the abstract, of the value of Bee, she liked to have the
whole of her; not to share her with somebody else. Certainly not with a "Miss Smith!"

"You see, I've been near Amy all my life; and she is so good to me—too good! She's years
older, but we are just like sisters, and I don't know how I shall get on without her. But if it
is to come near you, dear, saying good-bye won't be quite so hard."

"It will be frightfully nice if you do. We can do no end of things together. I suppose it's not
settled yet."

"No; only, if mother once takes to a plan, she doesn't soon give it up. So I'm very hopeful.
Just think! If I were always near you! And you were always coming in and out!"

"It would be frightfully nice!" repeated Magda, throwing into her voice what Bee would
expect to hear. But when she strolled away, she questioned within herself—was she glad?
Would she be more disappointed or more relieved if the scheme fell through?

The notion of introducing Beatrice Major to her home-circle did not quite appeal to her. The
Roystons held their heads high, and moved in county circles, and were extremely
particular as to whom they deigned to know. Bee herself was the dearest little creature—
pretty and lovable, sweet and kind; but she had been only two years in the school, and
Magda had met none of Bee's people. They might very easily fail to suit her people.

Beatrice, it was true, never seemed to mind being questioned about her home and
connections; but it was equally true that she never appeared to have very much to say—at
least of any such particulars as would impress the Royston imagination; and this was
suggestive. Magda had heard so much all her life about people's antecedents, that she
might be excused for feeling nervous. She had seen a photo of Bee's mother, and thought
her a very unattractive person; also a photo of Amy Smith, which was worse still. She
knew that Mrs. Major could not be too well off, for Bee's command of pocket-money was
by no means plentiful, and her wardrobe was limited.
They would probably live in some poky little house. And though Magda could talk grandly
about not caring what other people thought, and though personally she would not perhaps
mind about the said house, yet she would mind extremely if her own particular friend were
looked down upon by her home-folks. The very idea of Pen's air of mild disdain stung
sharply.

So altogether she felt that, if the plan failed, she would not be very sorry. But Bee might
on no account guess this.

Several weeks later came the day of parting; and once more Magda stood before Miss
Mordaunt with a lump in her throat.

"You will have to work steadily, if you do not mean to lose all you have gained, Magda."

"I know. I shall make a plan for every day, and stick to it."

"Except when home duties come between."

"I've no home duties. Pen goes everywhere with mother, and Merryl does all the little
useful fidgets. There's nothing left for me. Nobody will care what I'm after."

Miss Mordaunt studied the impressionable face. Some eager thought was at work below
the surface.

"What is it, my dear?"

"You always know when I've something on my mind. I've been thinking a lot lately. Miss
Mordaunt, I want to do something with my life. Not just to drift along anyhow, as so many
girls do. I want to make something of it. Something great, you know!"—and her eyes
glowed. "Do you think I shall ever be able? Does the chance come to everybody some time
or other? I've heard it said that it does."

"It may. Many miss the 'chance,' as you call it, when it does come. I should rather call it
'the opportunity.' What do you mean by 'something great'?"

"Oh—Why!—You know! Something above the common run. Like Grace Darling, or Miss
Florence Nightingale, or that Duchess who stayed behind in the French bazaar to be burnt
to death, so that others might escape. It was noblesse oblige with her, wasn't it? I think it
would be grand to do something of that sort,—that would be always remembered and
talked about."

"Perhaps so. But don't forget that what one is in the little things of life, one is also in the
great things. More than one rehearsal is generally given to us before the 'great
opportunity' is sent. And if we fail in the rehearsals, we fail then also."

"Yes—I know. And I do mean to work at my studies. But all the same, I should like to do
something, some day, really and truly great."

Miss Mordaunt looked wistfully at the girl. "Dear Magda—real greatness does not mean
being talked about. It means—doing the Will of God in our lives—doing our duty, and doing
it for Him."
CHAPTER II
WHAT WAS THE USE?

MANY months later that parting interview with Miss Mordaunt recurred vividly to Magda.

"What's the good of it all, I wonder?" she had been asking aloud.

And suddenly, as if called up from a far distance, she saw again Miss Mordaunt's face, and
heard again her own confident utterances.

It was a bitterly cold March afternoon. She stood alone under the great walnut tree in the
back garden—which was divided by a tall hedge from the kitchen garden. Over her head
was a network of bare boughs; and upon the grass at her feet lay a pure white carpet.
Some lilac bushes near had begun to show promise of coming buds; but they looked
doleful enough now, weighed down by snow.

She had with such readiness promised steady work in the future! And she had meant it
too.

The thing seemed so easy beforehand. And for a time she really had tried. But she had not
kept it up. She had not worked persistently. She had not "stuck" to her plans. The contrast
between intention and non-fulfilment came upon her now with force.

Six months had gone by of home-life, of emancipation from school control. Six months of
aimless drifting—the very thing she had resolved sturdily against.

"Oh, bother! What's the use of worrying? Why can't I take things as Pen does? Pen never
seems to mind." But she was in the grip of a cogitative mood, and thinking would not be
stayed.

She had begun well enough—had planned daily two hours of music, an hour of history, an
hour of literature, an hour alternately of French and German. It had all looked fair and
promising. And the whole had ended in smoke.

Something always seemed to come in the way. The children wanted a ramble. Or she was
sent on an errand. Or a caller came in. Or there was an invitation. Or—oftener and worse!
—disinclination had her by the throat.

Disinclination which, no doubt, might have been, and ought to have been, grappled with
and overcome. Only, she had not grappled with it. She had not overcome. She had yielded,
time after time.

It was so difficult to work alone; so dull to sit and read in her own room; so stupid to write
a translation that nobody would see; so tiresome to practice when there was none to
praise or blame. Not that she liked blame; and not that she was not expected to practice;
but no marked interest was shown in her advance; and she wanted sympathy and craved
an object. And it was so fatally easy to put off, to let things slide, to get out of the way of
regular plans. The fact that any time would do equally well soon meant no time.
This had been a typical day; and she reviewed it ruefully. A morning of aimless nothings;
the mending of clothes idly deferred; hours spent in the reading of a foolish novel; jars
with Penrose; friction with her mother; a sharp set-down from her father; then
forgetfulness of wrongs and resentment during a romp in the snow with Merryl and Frip—
till the younger girls were summoned indoors, leaving her to descend at a plunge from
gaiety to disquiet. Magda's variations were many.

She stood pondering the subject—a long-limbed well-grown girl, young in look for her
years, with a curly mass of red-brown hair, seldom tidy, and a pair of expressive eyes.
They could look gentle and loving, though that phase was not common; they could sparkle
with joy or blaze with anger; they could be dull as a November fog; they could, as at this
moment, turn their regards inwards with uneasy self-condemnation.

But it was a condemnation of self which she would not have liked anybody else to echo. No
one quicker, you may be sure, than Magda Royston in self-defence! Even now words of
excuse sprang readily, as she stood at the bar of her own judgment.

"After all, I don't see that it is my fault. I can't help things being as they are. And suppose
I had worked all these months at music and history and languages—what then? What
would be the good? It would be all for myself. I should be just as useless to other people."

A vision arose of the great things she had wished to do, and she stamped the snow flat.

"It's no good. I've no chance. There's nothing to be done that I can see. If I had heaps of
money to give away! Or if I had a special gift—if I could write books, or could paint
pictures! Or even if my people were poor, and I could work hard to get money for them!
Anything like that would make all the difference. As it is—well, I know I have brains of a
sort; better brains than Pen! But I don't see what I can do with them. I don't see that I
can do anything out of the common, or better than hundreds of other people do. And that
is so stupid. Not worth the trouble!"

"Mag-da!" sounded in Pen's clear voice.

"She never can leave me in peace! I'm not going indoors yet."

"Mag-da!" Three times repeated, was followed by—"Where are you? Mother says you are
to come."

This could not be disregarded. "Coming," she called carelessly, and in a slow saunter she
followed the boundary of the kitchen garden hedge, trailed through the back yard, stopped
to exchange a greeting with the house-dog as he sprang to the extent of his chain, stroked
the stately Persian cat on the door-step, and finally presented herself in the inner hall.

It was one of the oldest houses in the country town of Burwood; rather small, but antique.
Once upon a time it had stood alone, surrounded by its own broad acres; but things were
changed, and the acres had shrunk—through the extravagance of former Roystons—to
only a fair-sized garden. The rest of the land had been sold for building; and other houses
in gardens stood near. In the opinion of old residents, this was no longer real country; and
with new-comers, the Roystons no longer ranked as quite the most important people in the
near neighbourhood. Their means were limited enough to make it no easy matter for them
to remain on in the house, and they could do little in the way of entertaining. But they
prided themselves still on their exclusiveness.

Penrose stood waiting; a contrast to Magda, who was five years her junior. Not nearly so
tall and much more slim, she had rather pretty blue eyes and a neat figure, which
comprised her all in the way of good looks. Her manner towards Magda was superior and
mildly positive, though with people in general she knew how to be agreeable. Magda's air
in response was combative.

"Did you not hear me calling?"

"If not, I shouldn't be here now."

"I think you need not have kept me so long."

Magda vouchsafed no excuse. "What's up?" she demanded.

"Mother wants you in the drawing-room."

"What for?"

"She found your drawers untidy."

"Of course you sent her to look at them."

"I don't 'send' mother about. And I have not been in your room to-day."

"I understand!" Magda spoke pointedly.

Penrose glanced up and down her sister with critical eyes. A word of warning would be
kind. Magda seemed blissfully unconscious of her outward condition; and Pen had this
moment heard a ring at the front door, which might mean callers.

"You've done the business now, so I hope you're satisfied," Magda went on. "Mother would
never have thought of looking in my drawers, if you had not said something. I know! I did
make hay in them yesterday, when I couldn't find my gloves, but I meant to put them
straight to-night. It's too bad of you."

Pen's lips, parted for speech, closed again. If Magda chose to fling untrue accusations, she
might manage for herself. And indeed small chance was given her to say more. Magda
marched off, just as she was, straight for the drawing-room—her skirts pinned abnormally
high for the snow-frolic; her shoes encased in snow; her tam-o'-shanter half-covering a
mass of wild hair; her bare hands soiled and red with cold and scratched with brambles.

"Yes, mother. Pen says you want me."

She sent the words in advance with no gentle voice, as she whisked open the drawing-
room door. Then she stopped.

Mrs. Royston, a graceful woman, looked in displeasure towards the figure in the doorway;
for she was not alone.

Callers had arrived, as Pen conjectured; and through the front window might be seen two
thoroughbreds champing their bits, and a footman standing stolidly. Why had Pen given no
hint? How unkind! Then she recalled her own curt turning away, and knew that she was to
blame.

"Really!" with a faint laugh protested Mrs. Royston.

"So I thought we would look in for five minutes on our way back from Sir John's," the elder
caller was remarking in a manly voice.
She was a large woman, more in breadth and portliness than in height, and her
magnificent furs made her look like a big brown bear sitting on end. Her face too was large
and strongly outlined.

Magda guessed in a moment what her mother felt; for the Honourable Mrs. Framley was a
county magnate; the weightiest personality in more senses than one to be found for many
a mile around. A call from her was reckoned by some people as second only to a call from
Royalty. The girl's first impulse was to flee; but a solid outstretched hand commanded her
approach.

"Now, which of your young folks is this?" demanded Mrs. Framley, examining Magda
through an eye-glass. "Let me see—you've got—how many daughters? Penrose—Magda—
Merryl—Frances. I've not forgotten their names, though it's—how long?—since I was here
last. Months, I'm afraid. But this is not your neat Penrose; and my jolly little friend Merryl
can't have shot up to that height since I saw her; and Magda is out. Came out in the
autumn, didn't she? So who is this? A niece?"

"I'm Magda," the girl said in shamefaced confession, for Mrs. Royston seemed voiceless.

Mrs. Framley leant back in her chair, and laughed till she was exhausted.

"So that's a specimen of the modern young woman, eh?"—when she could regain her
voice. "My dear—" to Mrs. Royston—"pray don't apologise. It's I who should apologise. But
really—really—it's irresistible." She went into another fit, and emerged from it, wheezing.
"The child doesn't look a day over fifteen." The speaker wiped her eyes. "Don't send her
away. Unadulterated Nature is always worth seeing—eh, Patricia?"

Magda turned startled eyes in the direction of the second caller, a girl three or four years
older than herself, and the last person whom she expected to see. The last person,
perhaps, whom at that moment she wished to see. For despite Magda's boasted non-
chumminess with girls, this was the one girl whom she did, honestly and heartily, though
not hopefully, desire for a friend. She had fallen in love at first sight with Mrs. Framley's
niece, and had cherished her image ever since in the most secret recess of her heart.

"She'll think me just a silly idiotic school-girl!" flashed through Magda's mind, as she made
an involuntary movement forward with extended hand—a soiled hand, as already said,
scratched and slightly bleeding.

Patricia Vincent, standing thus far with amused eyes in the background, hesitated. She
was immaculately dressed in grey, with a grey-feathered hat, relieved by touches of
salmon-pink, and the daintiest of pale grey kid gloves. Contact with that hand did not quite
suit her fastidious sense. A mere fraction of a second—and then she would have
responded; but Magda, with crimsoning cheeks, had snatched the offending member away.

"I think you had better go and send Pen," interposed Mrs. Royston. Under the quiet words
lay a command, "Do not come back."

Magda fled, without a good-bye, and went to the school-room, where she flung herself into
an old armchair. The gas was low, but a good fire gave light; and she sat there in a
dishevelled heap, weighing her grievances.

It was too bad of Pen, quite too bad, not to have warned her! And now the mischief was
done. Patricia Vincent would never forget. Pen would go in and win; while she, as usual,
would be nowhere in the race.
And all because she had not first rushed upstairs, to smooth her hair and wash her hands!
Such nonsense!

As if Pen had not friends enough already! Just the single girl that she wanted for herself! If
she might have Patricia, Pen was welcome to the rest of the world. But that was always the
way! If one cared for a thing particularly, that thing was certain to be out of reach.

She was smarting still over the thought of that refused handshake; but her anger all went
in the direction of Pen, not of Patricia. Pen alone was to blame!

Presently the front door was opened and shut; and then Mrs. Royston came in, moving
with her usual graceful deliberation.

"What could have made you behave so, Magda?" she asked. "To come before callers in
such a state!"

Magda was instantly up in arms. "Pen never told me there were callers."

"She did not know it. She would have reminded you how untidy you were—certainly in no
condition to come into the drawing-room, even if I had been alone! But you show so much
annoyance if she speaks."

"Pen is always in the right, of course."

"That is not the way to speak to me. I would rather have had this happen before anybody
than before Mrs. Framley."

Magda shut her lips.

"Why did you not send Pen, as I told you?"

"I forgot."

"You always do forget. There is more dependence to be put upon Francie than upon you.
You think of nothing, and care for nothing, except your own concerns. I am disappointed in
you. It seems sometimes as if you had no sense of duty. And you ought to leave off giving
way to temper as you do. It is so unlike your sisters. Nothing ever seems right with you."

"I can't help it. It isn't my fault."

"Then you ought to help it. You are not a little child any longer."

Mrs. Royston hesitated, as if about to say more; but Magda held up her head with an air of
indifference, though invisible tears were scorching the backs of her eyes; and with a sigh
she left the room. Magda would let no tear fall. She was angry, as well as unhappy.

Why should she be always the one in disgrace—and never Pen? True, Pen was careful, and
neat, and sensible. All through girlhood Pen had been in the right. She had done her
lessons, not indeed brilliantly, but with punctuality and exactness. Her hair was always
neat; her stockings were always darned; her room was always in order; she never forgot
what she undertook to do; she never gave a message upside-down or wrong end before.
While Magda—but it is enough to say that in all these items she was the exact reverse of
Penrose.

This week she in her turn had charge of the school-room, which was also the play-room.
And the result, but for thoughtful Merryl, would have been "confusion worse confounded."
Mr. Royston was wont to declare that when his second daughter passed through a room,
she left such traces as are commonly left by a tropical cyclone. There was some truth in
the remark, if Magda happened to be in a tumultuous mood.

Penrose had her faults, as well as Magda, though somehow she was seldom blamed for
them. She had a knack of being always in the right, at least to outward appearance. No
doubt her faults were exaggerated by Magda; but they did exist. She wanted the best of
everything for herself; she alone must be popular; she could not endure that Magda should
do anything better than she did; she was not always strictly true. Magda saw and felt
these defects; but nobody else seemed to be aware of them; and she could prove nothing.
If she tried, she only managed to get into hot water, while Pen was sure to come off with
flying colours.

"And it will be just the same with Patricia Vincent," was the outcome of this soliloquy. "The
moment Pen guesses that I like her, she'll step in and oust me. I know she will."

CHAPTER III
ROBERT

WITH a creak, the door was cautiously opened. Somebody put in his head.

"All alone, Magda!"

Depression vanished, and the transformation in Magda's face was like an instantaneous
leap from November to June. In a moment her eyes were alight, her limbs alert.

"Rob!" she cried.

"Well, old girl! How are you?"

"You dear old fellow—I am glad."

The new-comer was about her own height, which though fairly tall for a girl could not be
so counted for a man. He was slim in make, like Pen; also, like Pen, scrupulously neat in
dress. Her eager welcome met with a quiet kiss; after which he seated himself; and his
eyes travelled over her, with a rather dubious expression.

"It's awfully jolly to have you here again. You never told us you were coming."

"I happened not to know it myself till this morning. What have you been after?"

"Just now? Playing in the snow."

Rob's gaze reached her shoes, and she laughed.

"Yes, I know! Of course, I ought to have changed them. But it didn't seem worth while. I
shall have to dress for dinner soon."

"And, meantime, you are anxious to start early rheumatism!"


"My dear Rob! I never had a twinge of it in my life—I don't know what it means."

"So much the better. It would be more sensible to continue in ignorance."

"Oh, all right. I'll be sensible, and change—presently. I really can't just now. I must have
you while I can. When the others know you are here, I shall not have a chance. Are you
going to stay?"

"One night. I must be off the first thing to-morrow morning."

"And I've oceans to say! Things that can't by any possibility be written."

"Fire away then. There's no time like the present."

"We shall be interrupted in two minutes. It's always the way! Why do things always go
contrary, I wonder? At least, they do with me. If I could only come and live with you, Rob!
—now!"

"That is to be your future life—is it?"

"Why, you know! Haven't we always said so? And whenever I am miserable, I always
comfort myself by looking forward to a home with you."

"What are you miserable about?"

"All sorts of things. Some days everything goes wrong and I can't get on with people. It's
not my fault. They don't understand me."

"I wonder whether you understand them?" murmured Rob.

"And there's nothing in life that's worth doing. Nothing in my life, I mean."

"Or rather—you have not found it yet."

"No, I don't mean that. I mean that there isn't anything. Really and truly!"

Rob said only, "H'm!"

"Yes, I dare say! But just think what I have to do. Tennis and hockey; cycling and walking;
mending my clothes and making blouses—not that I'm much good at that! Going to tea
with people I don't care a fig for; and having people here that I shouldn't mind never
setting eyes on again! Smothering down all I think and feel, because nobody cares.
Worrying and being worried, and all to no good. Nothing to show for the half-year that is
gone, and nothing to look to in the year that's begun. The months are just simply frittered
away, and no human being is the better for my being alive. It's not what I call Life. It is
just getting through time. Don't you see? It suits Pen well enough. So long as she gets a
decent amount of attention, she's happy. But I'm not made that way; and I can't see what
life is given us for, if it means nothing better."

When she stopped, pleased with her own eloquence, Rob merely remarked—

"Don't you think that bit of hard judgment might have been left out? It wasn't a needful
peroration."

Magda blushed; and Robert pondered.

"But, Rob—would you like to live such a life?"


Rob's gesture was sufficient answer.

"And yet you think I oughtn't to mind?"

"I beg your pardon. You are wrong to live it."

"But what can I do?"

"Find work. Take care that somebody is the better for your existence."

"I've tried. I can't. It's no good."

"There are always people to be helped—people you can be kind to—people you can cheer
up, when they feel dull."

"Pick up old ladies' stitches, I suppose. Interesting!"

"I did not know you wished to be interested. I thought you wanted to be of use."

"Well—of course! But that's so commonplace. I want to do something out of the ordinary
beat."

"You want some agreeable duty, manufactured to suit your especial taste!"

"Oh, bother! Somebody is coming. What a plague! And I have heaps more to say. Won't
you give me another talk?"

"I'll manage it."

He stood up to greet his mother, as she came in, followed by the two younger girls. The
news of his unexpected arrival seemed all at once to pervade the household.

Penrose entered next; and behind her Mr. Royston, a thick-set grey-haired man, of
impulsive manners, sometimes more kindly than judicious.

He was devoted to his family; not much given to books; ready to help anybody and
everybody who might appeal to him; generally more or less in financial difficulties, partly
from his inherited tendency to allow pounds and pence to slide too rapidly through his
fingers. A pleasant and genial man, so long as he did not encounter opposition; but it was
out of his power to understand why all the world should not agree with himself. His wife
gave in to him ninety-nine times in a hundred; and if, the hundredth time, she set her foot
down firmly, he gave in to her; for he was a most affectionate husband.

As for his daughters, he doted on them. Steady Penrose, useful Merryl, picturesque little
Frip, were everything that he desired. Magda alone puzzled him. He could not make out
what she wanted, or why she would not be content to fit in with others, to play games, to
sit and work, to do anything or nothing with equal content. Dreams and aspirations,
indeed! Nonsense! Humbug! What did girls want with such notions? They had to be good
girls, to do as they were told, and to make themselves agreeable. A vexed face annoyed
him beyond expression. He could not get over it. He could never ignore it. By his want of
tact, though with the kindest intentions, he often managed to put a finishing stroke to
Magda's uncomfortable moods.

"Why can't father leave me alone?" she sometimes complained.

Mr. Royston never did leave anybody alone, whether for weal or for woe. Nor did he ever
learn wisdom through his own mistakes.

You might also like