├── README.md ├── graph.js ├── server.R ├── ui.R └── www ├── testperf.csv └── testperf_extra.csv /README.md: -------------------------------------------------------------------------------- 1 | shiny-d3-plot 2 | ============= 3 | 4 | experiments with d3 and r integration with shiny 5 | 6 | Using the fine example offered by https://github.com/trestletech and http://www.trestletechnology.net/2012/12/reconstruct-gene-networks/, build a d3 bar plot of annual performance data for the S&P 500 and the Barclays US Aggregate Bond Index. Start with a local .csv file similar to the original example but eventually add on the ability to use live data from the web or from Axys. 7 | 8 | I do not have the ability to host on http://glimmer.rstudio.com for a web example. Until I get that, you can download the files, and then in R: 9 | 10 | require(shiny) 11 | 12 | runApp("C:\\path-to-download-location\\shiny-d3-plot") 13 | 14 | Unfortunately, my javascript and d3 abilities are weak, so hopefully those knowledgeable in those areas can build something way better than this simple example. -------------------------------------------------------------------------------- /graph.js: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 165 | -------------------------------------------------------------------------------- /server.R: -------------------------------------------------------------------------------- 1 | #thanks to https://www.trestletechnology.net/2012/12/reconstruct-gene-networks/ 2 | #for doing what I have been wondering how to do and had no clue how to accomplish 3 | #hopefully whoever reads this will attribute all the good code to him 4 | #and all the bad code/changes to me 5 | 6 | 7 | #enter any requires/library here 8 | #once I get more advanced, I will very likely add 9 | #require(quantmod) 10 | #require(PerformanceAnalytics) 11 | 12 | shinyServer(function(input, output) { 13 | 14 | #just as in the reference example, I'll start by loading a csv file 15 | #the hope in the future is to add Axys data or retrieve through getSymbols lots of data 16 | data <- reactive(function(){ 17 | 18 | if (input$dataSource == FALSE){ 19 | path <- input$url 20 | 21 | #translate relative paths to server-friendly paths 22 | if (substr(input$url, 0, 2) == "./"){ 23 | path <- paste("./www/", substring(input$url, 3), sep="") 24 | } 25 | } else{ 26 | df <- input$file 27 | path <- df$datapath 28 | } 29 | 30 | data <- read.csv(path, row.names=1) 31 | 32 | data.df <- cbind(rownames(data), data) 33 | colnames(data.df)[1] <- "Date" 34 | 35 | data.df 36 | }) 37 | 38 | output$perfbarplot <- reactive(function() { data() }) #when data changes, update the bar plot 39 | 40 | }) 41 | -------------------------------------------------------------------------------- /ui.R: -------------------------------------------------------------------------------- 1 | #thanks to https://www.trestletechnology.net/2012/12/reconstruct-gene-networks/ 2 | #for doing what I have been wondering how to do and had no clue how to accomplish 3 | #hopefully whoever reads this will attribute all the good code to him 4 | #and all the bad code/changes to me 5 | 6 | reactiveBar <- function (outputId) 7 | { 8 | HTML(paste("
", sep="")) 9 | } 10 | 11 | 12 | 13 | shinyUI(pageWithSidebar( 14 | headerPanel(HTML("Performance Comparison with shiny and d3.js thanks to Trestle Technology")), 15 | 16 | sidebarPanel( 17 | #selectInput(inputId = "dataSource", 18 | # label = "Source of the performance data:", 19 | # choices = c("Local", "Remote"), 20 | # selected = "Remote"), 21 | 22 | checkboxInput(inputId= "dataSource", label="Use a file stored on my local machine.", value=FALSE), 23 | 24 | conditionalPanel( 25 | condition = "input.dataSource == false", 26 | textInput(inputId="url", label="File URL:", value="./testperf.csv"), 27 | helpText(HTML("If you have trouble using this feature but want to analyze your own 38 | dataset, you can upload the file to a public URL using a tool like 39 | Dropbox or one of the many free upload 40 | sites.")) 41 | ), 42 | 43 | HTML("