Create an app for stock analysis with mock data. Generate mock daily price data for 5 tech stocks over the past year with standard fields (Open, Close, etc). Features: - Stock selector dropdown - Price trend charts - Basic stats (mean, volatility) - Moving averages - Volume analysis - Stock comparison Interactive elements: - Date range picker - Technical indicators - Chart type toggle Focus on clean visualization of realistic mock data.
Drop files here
or click to upload
library(shiny)
library(ggplot2)
library(dplyr)
library(tidyr)
library(plotly)
library(DT)
source("data.R")
source("utils.R")
ui <- fluidPage(
titlePanel("Stock Market Analysis Dashboard"),
sidebarLayout(
sidebarPanel(
selectizeInput("stock", "Select Stock(s)",
choices = unique(stock_data$symbol),
multiple = TRUE,
selected = "AAPL"),
dateRangeInput("dateRange", "Select Date Range",
start = min(stock_data$date),
end = max(stock_data$date)),
selectInput("chart_type", "Chart Type",
choices = c("Candlestick", "Line"),
selected = "Candlestick"),
checkboxGroupInput("technicals", "Technical Indicators",
choices = c("SMA20" = "sma20",
"SMA50" = "sma50",
"SMA200" = "sma200",
"Volume" = "volume"),
selected = "sma20")
),
mainPanel(
tabsetPanel(
tabPanel("Price Charts",
plotlyOutput("price_chart", height = "500px"),
conditionalPanel(
condition = "input.technicals.includes('volume')",
plotlyOutput("volume_chart", height = "200px")
)),
tabPanel("Statistics",
DT::dataTableOutput("stats_table")),
tabPanel("Comparison",
plotlyOutput("comparison_chart", height = "500px"))
)
)
)
)
server <- function(input, output, session) {
# Reactive filtered dataset
filtered_data <- reactive({
req(input$stock, input$dateRange)
stock_data %>%
filter(symbol %in% input$stock,
date >= input$dateRange[1],
date <= input$dateRange[2])
})
# Price Chart
output$price_chart <- renderPlotly({
plot_price_chart(filtered_data(),
input$chart_type,
input$technicals)
})
# Volume Chart
output$volume_chart <- renderPlotly({
plot_volume_chart(filtered_data())
})
# Statistics Table
output$stats_table <- DT::renderDataTable({
calculate_statistics(filtered_data())
})
# Comparison Chart
output$comparison_chart <- renderPlotly({
plot_comparison_chart(filtered_data())
})
}
shinyApp(ui = ui, server = server)
Hi! I can help you with any questions about Shiny and R. What would you like to know?