Search code examples
rshinyquantmodfinancial

R - Shiny can not find "container"


I am trying to create a basic financial shiny app that takes a company's ticker symbol as it's input and utilizes various functions in the quantmod package to return certain information (income statement, cash flow, etc.). I'm running into and error that reads, "ERROR: could not find function "container." I know most of the time shiny errors are due to not having a closing bracket somewhere but that doesn't seem to be the case and I haven't run into this error before when playing around. Any help appreciated.

ui.R

library(shiny)
shinyUI(
      fluidPage(
            titlePanel("Should You Invest"),
            sidebarLayout(
                  sidebarPanel(h3("How It Works"),
                        "You input the ticker symbol of a company, and this app returns the
                        Net Current Asset Value per Share, otherwise known as Grahams Rule", 
                        textInput("ticker",
                                  "Company Ticker",
                                  placeholder = "AAPL"),
                        submitButton("Submit"),
                        textOutput("last_price",
                                   "Last Traded Price"),
                        textOutput("NCAVPS",
                                   "Net Current Asset Value per Share")
                  ),
                  mainPanel(
                        tabsetPanel(type = "pills",
                                    tabPanel("Annual",
                                             tabsetPanel(type = "tabs",
                                                         tabPanel("Balance Sheet",
                                                                  textOutput("annual_bs")),
                                                         tabPanel("Cash Flow",
                                                                  textOutput("annual_cf")),
                                                         tabPanel("Income Statement",
                                                                  textOutput("annual_is"))
                                                      )
                                    ),
                                    tabPanel("Quarter",
                                             tabsetPanel(type = "tabs",
                                                         tabPanel("Balance Sheet",
                                                                  textOutput("quarter_bs")),
                                                         tabPanel("Cash Flow",
                                                                  textOutput("quarter_cf")),
                                                         tabPanel("Income Statement",
                                                                  textOutput("quarter_is"))
                                                      )
                                    )         
                        )
                  )
            )
      )
)

server.R

library(shiny)
shinyServer(function(input, output) {
      library(quantmod)
      change_ticker <- reactive(function() {
            ticker <- input$ticker
            adj_ticker <- getFin(ticker)
            financial <- get(adj_ticker)
            financial
      })      
      output$last_price <- renderTable(
            getQuote(ticker)
      )
      output$annual_bs <- renderText(
            viewFinancials(financial, type = "BS", period = "A")
      )
      output$annual_cf <- renderText(
            viewFinancials(financial, type = "CF", period = "A")
      )
      output$annual_is <- renderText(
            viewFinancials(financial, type = "IS", period = "A")
      )
      output$quarter_bs <- renderText(
            viewFinancials(financial, type = "BS", period = "Q")
      )
      output$quarter_cf <- renderText(
            viewFinancials(financial, type = "CF", period = "Q")
      )
      output$quarter_is <- renderText(
            viewFinancials(financial, type = "IS", period = "Q")
      )
})

Solution

  • textOutputs don't have labels, so this doesn't work:

    textOutput("last_price",
               "Last Traded Price"),
    textOutput("NCAVPS",
               "Net Current Asset Value per Share")
    

    The second argument is the container, a function that generates the HTML container. A label would have to be separate, like

    div(
      tags$b("Last Traded Price"),
      textOutput("last_price")
    )