Wrap rchart generator in a function