I'm attempting to draw a heatmap visualizing different measures of engagement along several social media platforms. I have followed the suggested workarounds to handle several of the problems between shiny and ggplot2, but am stuck on this last one:
My ui.R file
# ui.R
library(shiny)
# Define UI for application that draws a heat map
shinyUI(fluidPage(
# Application title
titlePanel("Social Media"),
# select platform and measure
sidebarLayout(
sidebarPanel(
selectInput("medium", "Choose a platform:",
choices = c("twitter", "facebook", "linkedin")),
selectInput("measure", "Choose a measure:",
choices = c("audience", "reach", "kudos", "engagement", "clicks"))
),
# plot heat of measure
mainPanel(
plotOutput('heat'))
)
))
my server.R file
server.R
library(shiny)
library(ggplot2)
library(dplyr)
library(readr)
social_media <- read_csv("data/social_media.csv")
# Define server logic required to draw a heat map
shinyServer(function(input, output) {
output$heat <- renderPlot({
plot_data <- reactive({
social_media %>%
filter(social_media$source==input$medium)
})
ggplot(plot_data(), aes_string(x="hour_of_day", y="day"),
environment = environment()) +
geom_raster(aes_string(fill="input$measure"))
})
})
Rather than the heat map I expect, I get a monochromatic plot where the fill appears to be the metric plotted as a factor: http://i.imgur.com/tA6kX7d.png) http://i.imgur.com/8RLU453.png
The variable names in my dataset correspond to the select inputs: Source: local data frame [6 x 20]
time date
(chr) (time)
1 03:55 PM 2014-01-02
2 03:30 PM 2014-01-03
3 04:30 PM 2014-01-06
4 06:04 PM 2014-01-07
5 11:53 AM 2014-01-08
6 04:15 PM 2014-01-08
Variables not shown: message text (chr), audience (int), reach (int), kudos (int), engagement (int), author (chr),
account name (chr), message URL (chr), clicks (int), tags (chr), source (chr), datetime (chr), date_time (time),
hour_of_day (int), day (fctr), week (dbl), month (fctr), year (dbl)
I don't know what else to do. Thoughts?