Clean some things up and get ready for Shiny.
This commit is contained in:
26
ledgerr-shiny/server.R
Normal file
26
ledgerr-shiny/server.R
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#
|
||||||
|
# This is the server logic of a Shiny web application. You can run the
|
||||||
|
# application by clicking 'Run App' above.
|
||||||
|
#
|
||||||
|
# Find out more about building applications with Shiny here:
|
||||||
|
#
|
||||||
|
# http://shiny.rstudio.com/
|
||||||
|
#
|
||||||
|
|
||||||
|
library(shiny)
|
||||||
|
|
||||||
|
# Define server logic required to draw a histogram
|
||||||
|
shinyServer(function(input, output) {
|
||||||
|
|
||||||
|
output$distPlot <- renderPlot({
|
||||||
|
|
||||||
|
# generate bins based on input$bins from ui.R
|
||||||
|
x <- faithful[, 2]
|
||||||
|
bins <- seq(min(x), max(x), length.out = input$bins + 1)
|
||||||
|
|
||||||
|
# draw the histogram with the specified number of bins
|
||||||
|
hist(x, breaks = bins, col = 'darkgray', border = 'white')
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
33
ledgerr-shiny/ui.R
Normal file
33
ledgerr-shiny/ui.R
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#
|
||||||
|
# This is the user-interface definition of a Shiny web application. You can
|
||||||
|
# run the application by clicking 'Run App' above.
|
||||||
|
#
|
||||||
|
# Find out more about building applications with Shiny here:
|
||||||
|
#
|
||||||
|
# http://shiny.rstudio.com/
|
||||||
|
#
|
||||||
|
|
||||||
|
library(shiny)
|
||||||
|
|
||||||
|
# Define UI for application that draws a histogram
|
||||||
|
shinyUI(fluidPage(
|
||||||
|
|
||||||
|
# Application title
|
||||||
|
titlePanel("Old Faithful Geyser Data"),
|
||||||
|
|
||||||
|
# Sidebar with a slider input for number of bins
|
||||||
|
sidebarLayout(
|
||||||
|
sidebarPanel(
|
||||||
|
sliderInput("bins",
|
||||||
|
"Number of bins:",
|
||||||
|
min = 1,
|
||||||
|
max = 50,
|
||||||
|
value = 30)
|
||||||
|
),
|
||||||
|
|
||||||
|
# Show a plot of the generated distribution
|
||||||
|
mainPanel(
|
||||||
|
plotOutput("distPlot")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
))
|
20
working.Rmd
20
working.Rmd
@ -9,12 +9,17 @@ output: html_document
|
|||||||
knitr::opts_chunk$set(echo = TRUE)
|
knitr::opts_chunk$set(echo = TRUE)
|
||||||
```
|
```
|
||||||
|
|
||||||
Should use this document for actual operations and keep actual functions in another document for the public [GitHub repo](https://github.com/mattbk/ledgerr). Shiny will be set up at https://www.shinyapps.io/admin/#/dashboard.
|
|
||||||
|
|
||||||
```{r}
|
```{r}
|
||||||
# Use https://github.com/maxconway/gsheet
|
# Use https://github.com/maxconway/gsheet
|
||||||
library(gsheet)
|
library(gsheet)
|
||||||
|
|
||||||
|
# Use the functions in ledgerr (the package that is part of this project) but don't load the package itself--this will let us deploy to Shiny.io more easily.
|
||||||
|
library(R.utils) #for sourceDirectory()
|
||||||
|
sourceDirectory("ledgerr/R")
|
||||||
|
|
||||||
|
# For Shiny
|
||||||
|
library(rsconnect)
|
||||||
|
|
||||||
# Pull Google sheet locations from another file (journal1, journal2, etc.)
|
# Pull Google sheet locations from another file (journal1, journal2, etc.)
|
||||||
source("config.R")
|
source("config.R")
|
||||||
|
|
||||||
@ -39,15 +44,18 @@ journal$Credit<-as.numeric(sub(",","",journal$Credit))
|
|||||||
|
|
||||||
################# work in progress
|
################# work in progress
|
||||||
|
|
||||||
# This could replace net.acc, check numbers
|
## This could replace net.acc, check numbers
|
||||||
a<-aggregate(cbind(Credit,Debit=-Debit)~Account,data=journal,function(x) sum(x, na.rm=TRUE),na.action="na.pass")
|
a<-aggregate(cbind(Credit,Debit=-Debit)~Account,data=journal,function(x) sum(x, na.rm=TRUE),na.action="na.pass")
|
||||||
|
# Select by class (modify to include dates)
|
||||||
|
#a<-aggregate(cbind(Credit,Debit=-Debit)~Account,data=journal[journal$Class %in% "Bikecicle",],function(x) sum(x, na.rm=TRUE),na.action="na.pass")
|
||||||
# na.pass: http://stackoverflow.com/a/16844940/2152245
|
# na.pass: http://stackoverflow.com/a/16844940/2152245
|
||||||
|
# This is a column rename on the fly: "Debit=-Debit"
|
||||||
# Calculate net column
|
# Calculate net column
|
||||||
a$Net<-rowSums(a[,2:3],na.rm=T)
|
a$Net<-rowSums(a[,2:3],na.rm=T)
|
||||||
# Calculate total--need to clean up
|
# Calculate total--need to clean up
|
||||||
colSums(a[-1])
|
colSums(a[-1])
|
||||||
|
|
||||||
# This is a column rename on the fly: "Debit=-Debit"
|
|
||||||
|
|
||||||
# This could replace net.class, check numbers
|
# This could replace net.class, check numbers
|
||||||
a<-aggregate(cbind(Credit,Debit=-Debit)~Class,data=journal,function(x) sum(x, na.rm=TRUE),na.action="na.pass")
|
a<-aggregate(cbind(Credit,Debit=-Debit)~Class,data=journal,function(x) sum(x, na.rm=TRUE),na.action="na.pass")
|
||||||
@ -56,9 +64,5 @@ a$Net<-rowSums(a[,2:3],na.rm=T)
|
|||||||
# Calculate total--need to clean up
|
# Calculate total--need to clean up
|
||||||
colSums(a[-1])
|
colSums(a[-1])
|
||||||
|
|
||||||
# This could also replace net.class if in the right layout (http://nicercode.github.io/guides/repeating-things/)
|
|
||||||
class.split<-split(journal,journal$Class)
|
|
||||||
sapply(class.split, net)
|
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
Reference in New Issue
Block a user