Learn R Programming

googleAnalyticsR (version 0.7.1)

ga_model_tweet: Upload an interactive visualisation so it can be embedded in a tweet

Description

Inspired by https://datatitian.com/how-to-turn-your-ggplot2-visualization-into-an-interactive-tweet/ this uploads your model output into Google Cloud storage, in the right format to embed in a tweet

Usage

ga_model_tweet(model_output, twitter, title, bucket, image = "")

Arguments

model_output

A ga_model_result object created by ga_model

twitter

Your twitter handle e.g. @holomarked

title

Twitter preview card title text

bucket

The GCS bucket to upload to

image

An optional image to display before the visualition runs

Details

This should work with all model outputs that are using library(htmlwidgets)

If using plotly, you need an account to use plotly_IMAGE to generate the preview image.

If you don't use a preview image, a generic one will be supplied instead.

You need to authenticate with `googleCloudStorageR` before running this function so it can upload the appropriate files and make them public.

https://cards-dev.twitter.com/validator is useful to test what it will look like on Twitter.

See Also

Other GA modelling functions: ga_model_edit, ga_model_example, ga_model_load, ga_model_make, ga_model_save, ga_model_write, ga_model

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
  library(googleAnalyticsModelR)
  library(googleAnalyticsR)
  library(plotly)

  # create your htmlwidget output - in this case plot.ly
  output <- ga_time_normalised(81416156, interactive_plot = TRUE)
  
  # if you have a plot.ly account, you can generate a static image
  plotly_IMAGE(output$plot, out_file = "tweet.png")

  # now upload - assumes auto-authentication with googleCloudStorage
  library(googleCloudStorageR)
  ga_model_tweet(output, 
                 "@HoloMarked", 
                 "Test2 ga_model twitter upload", 
                 bucket = "mark-edmondson-public-read",
                 image = "tweet.png")
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab