Hello I am attempting to create a Shiny Dashboard that can show stock prices over time and update each day.
#Packages:
library(shiny)
library(shinydashboard)
library(plotly)
library(DT)
library(rsconnect)
library(tidyquant)
#Stock Collection API.
Stock_Table <- tq_get(c("AAPL","MSFT","META"),
from = "1900-01-01",
to = Sys.Date(),
get = "stock.prices")
#Creating the UI.
ui<-dashboardPage(skin="red",
dashboardHeader(title = "Tyler's Dashboard"),
dashboardSidebar(
sidebarMenu(
menuItem("Stock", tabName = "Stock", icon = icon("money-bill-alt"))
)
),
dashboardBody(
tabItems(
tabItem("Stock",
box(plotlyOutput("stock_plot"), width=10),
box(
dateInput("start_date", "Start Date:", value = "2012-02-29"),
dateInput("end_date", "End Date:", value = "2012-02-29"),
selectInput("measure", "Measure",
c("open", "high","low","close")),
selectInput("ticker", "Ticker",
c("AAPL","META","MSFT")),
width = 2)
)
),
)
)
#Creating the Server
server<- function(input, output){
output$stock_plot <- renderPlotly({
plot_ly(Stock_Table[which(Stock_Table$symbol==input$ticker),], x = ~Stock_Table$date, y = ~Stock_Table[[input$measure]], type = 'scatter', mode = 'lines')
})
}
shinyApp(ui, server)
Note that I am attempting to use a 'which' statement to restrict the data set within plotly to only the ticker of interest. Currently the 'passback' from the user input does not seem to be working. Also note that the following line of code works properly when run by itself:
plot_ly(Stock_Table[which(Stock_Table$symbol=="MSFT"),], x = ~date, y = ~close, type = 'scatter', mode = 'lines')
Any recommendations on how to get this to work?