tests/test_odbc.R

options("connectionObserver" = NULL)

library(ECShiny)
library(DBI)
library(odbc)
library(dplyr)
library(dbplyr)
library(RPostgreSQL)


pg <- dbConnect(odbc::odbc(), dsn = "DM_MARCO")

# Conexão com Data Mart via DPLYR
pg <- src_postgres(dbname = "dm_marco",
                   host = 'localhost',
                   port = 5432,
                   user = "teste",
                   password = "teste")

# Conectar tabelas de dados granuladas (Carregamento dinâmico) ----

# Painel Produto
#td_nfe_medicamentos <<- tbl(con,in_schema("sagres_medicamentos","td_nfe_medicamentos")) %>% collect %>% as.data.frame
df1 <- tbl(pg,in_schema("sagres_medicamentos","td_painel_produto"))
df2 <- readRDS("~/Dropbox/MARCO/produtos/aplicacoes/APP/sagres-medicamentos/data/td_painel_produto.rds")

df1 <- df1 %>%
  group_by("Ano"=ano) %>%
  summarise(
    Total = sum(vlote, na.rm = TRUE)
  ) %>%
  ungroup %>%
  collect %>%
  as.data.frame

df2 <- df2 %>%
  group_by("Ano"=ano) %>%
  summarise(
    Total = sum(vlote, na.rm = TRUE)
  ) %>%
  ungroup %>%
  collect %>%
  as.data.frame

on.exit(dbDisconnect(pg), add = TRUE)

eBar(
  data = df1,
  x = "Ano",
  xdate = "text",
  y = "Total")
lemaufpb/ECShiny documentation built on July 20, 2018, 3:37 p.m.