library(shiny)
library(reshape2)
library(ggplot2)
library(ggthemes)
library(scales)
BVC <- read.csv("datos/datos.csv", sep=";", dec=",",stringsAsFactors=FALSE)
BVC$FECHA <- as.Date(BVC$FECHA,format="%Y/%m/%d")
names(BVC) = gsub("\\.", "", names(BVC))
shinyUI(fluidPage(
titlePanel("Indicadores BVC"),
sidebarPanel(
selectInput("activos", label = h6("Activo"),
choices = names(BVC)[-1],
selected = "COLCAP"),
selectizeInput("sectores", label = h6("Por Sector"), choices = list(
Petroleras= c("Ecopetrol", "Pacific.Rubiales","Canacol"),
Bancos= c("Bogota","Occidente","Bancolombia","Pref.Bancolombia",
"PF.Helmbank","Davivienda","PF.Aval"),
Industrial=c("Acerias","Celcia","Cemargos","Cemex","Coltejer","Conconcreto","Enka",
"Fabricato","Isa","Mineros","Tablemac","Terpel"),
Inversiones=c("Grupo.Aval","Grupo.Sura","InverArgos","Nutresa","Valorem"),
Publico=c("EEB","ETB","Isagen"),
Otras=c("BVC","Corficol","Odinsa","Avianca")
), multiple= FALSE),
dateRangeInput("rango", label = h6("Rango Fecha:"),
start = Sys.Date()-1831, end =Sys.Date()-16,
min=Sys.Date()-1831,max= Sys.Date()-16,
format = "yyyy/mm/dd",separator = " - ",
language="es")
),
mainPanel(
tabsetPanel(
tabPanel("Precios", plotOutput("precios")),
tabPanel("Estadisticas", tableOutput("estadisticas")),
tabPanel("Multiplos", tableOutput("multiplos")),
tabPanel("Tecnico", plotOutput("tecnico")),
tabPanel("Macro", tableOutput("macro")),
tabPanel("Estrategia Trading", tableOutput("estrategia")),
id = "conditionedPanels")
)
))
I have worked around this issue and i have not been able to figure it out. I have checked stackoverflow as well as google groups but to no avail. The issue is with the date format. whenever I use in the server.R file "FECHA" which is the date variable in the file BVC file I can plot the charts but they are not dynamic becuase i cannot use x=input$rango which is the inputid I defined earlier in the ui.R file. and when I use x=input$rango I get the error. Yhe thing is I want the daterangeinput to display the charts according to the date set by the user.
This a preview of the file
head(BVC)[,1:6]
FECHA IGBC COLCAP COL20 Ecopetrol Bogota
1 2009-12-23 11511.72 1364.13 1102.92 2425 33800
2 2009-12-24 11614.81 1372.72 1113.38 2480 34080
3 2009-12-25 11614.81 1372.72 1113.38 2480 34080
4 2009-12-28 11562.42 1365.06 1109.84 2475 33800
5 2009-12-29 11568.90 1366.35 1111.25 2480 33900
6 2009-12-30 11602.14 1366.85 1115.43 2485 33800
file ui.R
library(shiny)
library(reshape2)
library(ggplot2)
library(ggthemes)
library(scales)
BVC <- read.csv("datos/datos.csv", sep=";", dec=",",stringsAsFactors=FALSE)
BVC$FECHA <- as.Date(BVC$FECHA,format="%Y/%m/%d")
names(BVC) = gsub("\\.", "", names(BVC))
shinyUI(fluidPage(
titlePanel("Indicadores BVC"),
sidebarPanel(
selectInput("activos", label = h6("Activo"),
choices = names(BVC)[-1],
selected = "COLCAP"),
selectizeInput("sectores", label = h6("Por Sector"), choices = list(
Petroleras= c("Ecopetrol", "Pacific.Rubiales","Canacol"),
Bancos= c("Bogota","Occidente","Bancolombia","Pref.Bancolombia",
"PF.Helmbank","Davivienda","PF.Aval"),
Industrial=c("Acerias","Celcia","Cemargos","Cemex","Coltejer","Conconcreto","Enka",
"Fabricato","Isa","Mineros","Tablemac","Terpel"),
Inversiones=c("Grupo.Aval","Grupo.Sura","InverArgos","Nutresa","Valorem"),
Publico=c("EEB","ETB","Isagen"),
Otras=c("BVC","Corficol","Odinsa","Avianca")
), multiple= FALSE),
dateRangeInput("rango", label = h6("Rango Fecha:"),
start = Sys.Date()-1831, end =Sys.Date()-16,
min=Sys.Date()-1831,max= Sys.Date()-16,
format = "yyyy/mm/dd",separator = " - ",
language="es")
),
mainPanel(
tabsetPanel(
tabPanel("Precios", plotOutput("precios")),
tabPanel("Estadisticas", tableOutput("estadisticas")),
tabPanel("Multiplos", tableOutput("multiplos")),
tabPanel("Tecnico", plotOutput("tecnico")),
tabPanel("Macro", tableOutput("macro")),
tabPanel("Estrategia Trading", tableOutput("estrategia")),
id = "conditionedPanels")
)
))
file server.R
library(shiny)
library(reshape2)
library(ggplot2)
library(ggthemes)
library(scales)
BVC <- read.csv("/datos/datos.csv", sep=";", dec=",",stringsAsFactors=FALSE)
BVC$FECHA <- as.Date(BVC$FECHA,format="%Y/%m/%d")
names(BVC) = gsub("\\.", "", names(BVC))
shinyServer(function(input, output) {
output$precios <- renderPlot({
g1 <- ggplot(BVC,na.rm=TRUE,environment = environment())
g1 <- g1 + geom_line(aes_string(x=input$rango,y=input$activos,
colour= "input$activos"),size=1) +
scale_x_date(breaks = date_breaks("3 months"),labels = date_format("%b-%y")) +
theme_economist(dkpanel=TRUE) + scale_colour_economist() +
scale_y_continuous(breaks = pretty_breaks(n=7), labels=dollar) +
theme(legend.position="none") + xlab("fecha")
print(g1)
})
})