How to plot a graph in the UI (shiny), having as origin the function "stock.R", which generates variable "everything", with 2 columns

0

Kindly, if you can help, you will be very grateful. I have read several websites and I did not understand how to do it, because I still learn Shiny.

The code of the function "stock.R", and the following:

stock<- function(ticker,rx){
re<- ({as.numeric(rx)})
#re=0

#ticker="vale3"
p1=ticker
p=140
#re=0#retrocede candles de 15 minutos
options(max.print=15)##qtdadde reg para impressao na tela

p1<-toupper(p1)
ta=length(p1)

options(max.print=15)##qtdadde reg para impressao na tela
p2="https://finance.google.com/finance/getprices?q="
p4="&x=BVMF&i=900&p=100d&f=c"

looping

URL<-paste(p2,p1,p4,sep="")
xx<- read.csv(URL)
colnames(xx)[1] <- "co1"  #muda none EXCHANGE.#DBMF para close
c1=(xx$co1)
t1=length(c1)
c2=c1[(t1-500):t1]
c3 <- c2[ c2 != "TIMEZONE_OFFSET=-180" ]
c4<-as.numeric(as.character(c3))
n=length(c4)
time=seq(1,n,by=1)
clo=tail(c4,n=1)
tudo<- cbind(time,c4)
colnames(tudo)<- c("tempo","preco")
tudo
return(paste0("Close.: ",clo))
}

The UI code, and the following:

library(shiny)

ui = shinyUI(fluidPage(
  h3("Pesquisa:"),
    fluidRow(
    column(6,selectizeInput("ticker", "Selecione Ativo Desejado,ou Digite Nome da Empresa", width="100%",multiple=TRUE,
                            choices = list("AMBEV S/A"="ABEV3","BRASIL"="BBAS3","BRADESCO"="BBDC3"))), 

    column(3,selectizeInput("rx", "Retroceder x Candles de 15 Minutos", width="100%",
                            choices = list(0,1,2))),

    column(3,actionButton(inputId = "input_action", label = "Processa os Dados.???"))

  ),

  mainPanel(
    h5(textOutput("caption")),

  tableOutput("saida")),
   plotOutput("plot")

The code server, and the following:

library(shiny)
source("stock.R",local = TRUE)

shinyServer(function(input,output) {        

  observeEvent(input$input_action, {

    ticker= input$ticker

    rx = input$rx


    output$saida <- renderTable({
    stock(ticker,rx)

    }) 

    output$plot <- renderPlot({ 
      stock(ticker,rx)
      plot(tudo)
    })
  })

})
    
asked by anonymous 14.03.2018 / 19:45

0 answers