dreamRs / shinylogs

Logs for Shiny apps
https://dreamrs.github.io/shinylogs/
96 stars 13 forks source link

How can I replicate the graphs of ggplot2 #9

Closed cayetanaasencio closed 2 years ago

cayetanaasencio commented 3 years ago

Hi. Thanks for this amazing pack.

Please, How can I replicate the graphs of ggplot2 to track activity?

I see that for each session a log is generated, so I would like to join all the files and make the graphs like those of ggplot2, to analyze the activity, for example, the number of clicks on a button.

pvictor commented 3 years ago

Sorry for late answer. I don't have something clean to share, it's in my todo for a while.

You can recreate the first two plots like this:

library(data.table)
library(shinylogs)
library(ggplot2)

logs <- read_json_logs("path/to/logs/")

# Number of connection per applications
ggplot(data = logs$session[, .N, by = app][order(N)]) +
  aes(x = factor(app, app), y = N) +
  geom_col(fill = "#112446") +
  coord_flip() +
  scale_y_continuous(expand = expansion(c(0, 0.1))) +
  labs(
    title = "Number of connections per application",
    x = NULL, y = "total number of connections"
  ) +
  theme_minimal()

# Number of connections per day
logs$session[, date_server_connected := as.Date(substr(server_connected, 1, 10))]
ggplot(data = logs$session[, .N, by = date_server_connected][order(date_server_connected)]) +
  aes(x = date_server_connected, y = N) +
  geom_col(fill = "#112446") +
  scale_y_continuous(expand = expansion(c(0, 0.1))) +
  labs(
    title = "Number of connections per day",
    x = NULL, y = "number of connections"
  ) +
  theme_minimal()

Victor