Shiny + Quantmod

513 views
Skip to first unread message

billy am

unread,
Aug 30, 2014, 12:14:28 AM8/30/14
to shiny-...@googlegroups.com
Hi Everyone ,

I am trying to start a simple Shiny + quantmod and having some slight issues , perhaps I am still noob at Shiny. Can anyone help? Thanks

-----------------------------------------------------

ui.R


library(shiny)
shinyUI(pageWithSidebar(headerPanel("Quantmod Plot"),
                        sidebarPanel(selectInput("stock_name",
                                                 "Select : ",
                                                 list("AAPL", "MSF"))
                                   
                        ),
                        mainPanel(tabPanel("Plot", plotOutput("plot")))
))

-----------------------------------------------------------------------------------

server.R

library(shiny)
library(quantmod)

shinyServer(function(input, output){


a <- getSymbols(input$stock_name, src = "yahoo",from = as.Date("2010-01-01"), to = as.Date("2014-01-01"))
output$plot <- renderPlot({ chartSeries(a) })

})

------------------------------------------------

The error as follows ,

Error in .getReactiveEnvironment()$currentContext() :
  Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
"

Thanks!

Billy


billy am

unread,
Aug 30, 2014, 2:01:28 AM8/30/14
to shiny-...@googlegroups.com
Updated as follows ,

ui.R


library(shiny)
shinyUI(pageWithSidebar(headerPanel("Quantmod Plot"),
                        sidebarPanel(
                          textInput("stock_name", "Enter Stock Name:", "AAPL"),
                         submitButton("Submit")

                                   
                        ),
                        mainPanel(tabPanel("Plot", plotOutput("plot")))
))

------------------------------

server.R

library(shiny)
library(quantmod)

shinyServer(function(input, output){



abc <- reactive({ abc <- getSymbols(input$stock_name,
src = "yahoo",from = as.Date("2010-01-01"), to = as.Date("2014-01-01")) })
output$plot <- renderPlot({ chartSeries(abc) })

})

----------------------------

Now the error is

chartSeries requires an xtsible object

ZJ

unread,
Sep 1, 2014, 12:12:54 AM9/1/14
to shiny-...@googlegroups.com
reactives need to have () at the end to so 

output$plot <- renderPlot({ chartSeries(abc()) })

I suspect the above also won't work. Try type "?chartSeries" into the console and read the documentation perhaps? No sure if this would help.

billy am

unread,
Sep 1, 2014, 12:52:48 AM9/1/14
to shiny-...@googlegroups.com
Hi thanks for the suggestion. Found a reactive example in one of the gallery so managed to resolve the error.

Ian McMurry

unread,
Jul 17, 2015, 10:39:04 AM7/17/15
to shiny-...@googlegroups.com
Hi,

I saw that you had the same problem that I have. You've also figured it out, and I was wondering if you could show me what you did to resolve the "chartSeries requires an xtsible object" error .

Thanks,
Reply all
Reply to author
Forward
0 new messages