A simple shiny interface to retrieve stock information

Posted on Nov 25, 2014

Demo day: Sept 16, 2014.
Displaying Capture.PNG

Contributed by Yide Pan.
Yide took the CORP-R 001 class with Vivian Zhang (Roche R Programming
Beginner) in Aug, 2014.

This post was based on his final project submission.

Goal: Get the Chinese stock information base on input stock code.
This project is aimed to retrieve and display stock information using shiny.

Data Prep

Sina is the ideal data source for China's stock infomration , we can get data using such kind of code,  however sina.com can provide more precise data to minutes level.

data do.call(rbind,xmlToList(data))

But the data from sina is not well orgnized, need spent time to clean and orgnize, my main goal is to use shiny, so I directly use quantmod and go with yahoo as data source.


Here is server end code, very simple, it's amazing R can handle the data in such a performat way.
if (!require(quantmod)) {
stop("This app requires the quantmod package. To install it, run 'install.packages("quantmod")'.n")

# Download data for a stock if needed, and return the data
require_symbol if (is.null(envir[[symbol]])) {
envir[[symbol]] }


shinyServer(function(input, output) {

# Create an environment for storing data

# Make a chart for a symbol, with the settings from the inputs
make_chart symbol_data #TA_STR chartSeries(symbol_data,
name = symbol,
type = input$chart_type,
subset = paste("last", input$time_num, input$time_unit),
#log.scale = input$log_y,
theme = "white")

output$plot_1 output$plot_2 output$plot_3 output$plot_4 output$plot_5 })

The front end code, mainly invoke the build in compoent.
headerPanel("炒股神器 发财大计"),

textInput(inputId = "stock1", label = "股票1"),
textInput(inputId = "stock2", label = "股票2"),
textInput(inputId = "stock3", label = "股票3"),
textInput(inputId = "stock4", label = "股票4"),
textInput(inputId = "stock5", label = "股票5")
// input box to manipulate stock code

selectInput(inputId = "chart_type",
label = "图形",
choices = c("蜡烛图" = "candlesticks",
"火柴图" = "matchsticks",
"柱形图" = "bars",
"线型图" = "line")

p(strong("日期范围 (从现在起倒推)")),
sliderInput(inputId = "time_num",
label = "时间个数",
min = 1, max = 24, step = 1, value = 6),

selectInput(inputId = "time_unit",
label = "时间单位",
choices = c("日" = "days",
"周" = "weeks",
"月" = "months",
"年" = "years"),
selected = "Months")

#checkboxInput(inputId = "log_y", label = "log y axis", value = FALSE)

conditionalPanel(condition = "input.stock1",
div(plotOutput(outputId = "plot_1"))),//invoke the sever function

conditionalPanel(condition = "input.stock2",
div(plotOutput(outputId = "plot_2"))),//invoke the sever function

conditionalPanel(condition = "input.stock3",
div(plotOutput(outputId = "plot_3"))),//invoke the sever function

conditionalPanel(condition = "input.stock4",
div(plotOutput(outputId = "plot_4"))),//invoke the sever function

conditionalPanel(condition = "input.stock5",
plotOutput(outputId = "plot_5")) //invoke the sever function

Shiny is very powerful, as I am informatics associate who will use various tools to handle data, and present them to scientists. Many time I meet the problem how to create a orgnized interface on top of the data I sorted out, and let user gain the flexibility to analyze data on multiple dimensions. Shiny and R is a good solution, but I still need to figure out a quick way to deploy shiny to my user.

I'd like to thanks to Vivian and her team, they give me a very vivid lesson can utilize new technology help me speed up the data process work!

About Author

Related Articles

Leave a Comment

No comments found.

View Posts by Categories

Our Recent Popular Posts

View Posts by Tags

#python #trainwithnycdsa 2019 airbnb Alex Baransky alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus API Application artist aws beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep Bundles California Cancer Research capstone Career Career Day citibike clustering Coding Course Demo Course Report D3.js data Data Analyst data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization Deep Learning Demo Day Discount dplyr employer networking feature engineering Finance Financial Data Science Flask gbm Get Hired ggplot2 googleVis Hadoop higgs boson Hiring hiring partner events Hiring Partners Industry Experts Instructor Blog Instructor Interview Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter lasso regression Lead Data Scienctist Lead Data Scientist leaflet linear regression Logistic Regression machine learning Maps matplotlib Medical Research Meet the team meetup Networking neural network Neural networks New Courses nlp NYC NYC Data Science nyc data science academy NYC Open Data NYCDSA NYCDSA Alumni Online Online Bootcamp Online Training Open Data painter pandas Part-time Portfolio Development prediction Prework Programming PwC python Python Data Analysis python machine learning python scrapy python web scraping python webscraping Python Workshop R R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn Selenium sentiment analysis Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau team TensorFlow Testimonial tf-idf Top Data Science Bootcamp twitter visualization web scraping Weekend Course What to expect word cloud word2vec XGBoost yelp