Time-dependent variational principle for the expectation value of an observable: Mean-field applications