Skip to content

Commit

Permalink
Merge pull request #12 from rsquaredacademy/develop
Browse files Browse the repository at this point in the history
Fix app
  • Loading branch information
aravindhebbali authored May 4, 2018
2 parents 7988b67 + 56fff1f commit 40edf0f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* linguist-vendored
*.R linguist-vendored=false
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ warnings_are_errors: true
sudo: false

r:
- 3.2
- oldrel
- release
- devel
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: rfm
Title: Recency, Frequency and Monetary Value Analysis
Version: 0.1.0
Version: 0.1.1
Authors@R: person("Aravind", "Hebbali", email = "[email protected]", role = c("aut", "cre"))
Description: Tools for RFM (recency, frequency and monetary value) analysis.
Generate RFM score from both transaction and customer level data. Visualize the
Expand All @@ -13,7 +13,7 @@ License: MIT + file LICENSE
URL: https://github.com/rsquaredacademy/rfm, https://rfm.rsquaredacademy.com/
BugReports: https://github.com/rsquaredacademy/rfm/issues
Depends:
R (>= 3.2.4)
R (>= 3.2)
Imports:
assertthat,
dplyr,
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# rfm 0.1.1

Patch release to fix the shiny app.

# rfm 0.1.0

This is a minor release for bug fixes and enhancements.
Expand Down
31 changes: 17 additions & 14 deletions inst/application/logic/logic_segments.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ output$segment_prep <- renderUI({
})

segment_names <- reactive({

ncol <- as.integer(input$n_segments)

collect <- list(lapply(1:ncol, function(i) {
Expand Down Expand Up @@ -114,22 +114,24 @@ monetary_upper <- reactive({
ncol <- as.integer(input$n_segments)

collect <- list(lapply(1:ncol, function(i) {

input[[paste("monetary_interval_", i)]]
}))

collect[[1]] %>%

map_int(2)

})

prep_segment <- eventReactive(input$button_create_segments, {

rfm_score_table <-
comp_rfm_score() %>%
use_series(rfm)
rfm_score_table <-
rfm_final_score$a %>%
use_series(rfm)

for (i in seq_len(input$n_segments)) {
rfm_score_table$segment[((rfm_score_table$recency_score %>% between(recency_lower()[i], recency_upper()[i])) &
rfm_score_table$segment[((rfm_score_table$recency_score %>% between(recency_lower()[i], recency_upper()[i])) &
(rfm_score_table$frequency_score %>% between(frequency_lower()[i], frequency_upper()[i])) &
(rfm_score_table$monetary_score %>% between(monetary_lower()[i], monetary_upper()[i])))] <- segment_names()[i]
}
Expand All @@ -140,20 +142,21 @@ prep_segment <- eventReactive(input$button_create_segments, {
select(
customer_id, segment, rfm_score, transaction_count, recency_days,
amount

)

})

output$segment_out <- renderDataTable({
prep_segment()
prep_segment()
})

output$segment_size_out <- renderPrint({

prep_segment() %>%
count(segment) %>%
arrange(desc(n)) %>%
rename(Segment = segment, Count = n) %>%
rename(Segment = segment, Count = n) %>%
kable() %>%
kable_styling(full_width = TRUE, font_size = 30)

Expand All @@ -165,13 +168,13 @@ fill_segments <- reactive({

output$segment_average_recency <- renderPlot({

data <-
data <-
prep_segment() %>%
group_by(segment) %>%
select(segment, recency_days) %>%
summarize(median(recency_days)) %>%
rename(segment = segment, avg_recency = `median(recency_days)`) %>%
arrange(avg_recency)
arrange(avg_recency)

n_fill <- nrow(data)

Expand All @@ -188,13 +191,13 @@ output$segment_average_recency <- renderPlot({

output$segment_average_frequency <- renderPlot({

data <-
data <-
prep_segment() %>%
group_by(segment) %>%
select(segment, transaction_count) %>%
summarize(median(transaction_count)) %>%
rename(segment = segment, avg_frequency = `median(transaction_count)`) %>%
arrange(avg_frequency)
arrange(avg_frequency)

n_fill <- nrow(data)

Expand All @@ -211,13 +214,13 @@ output$segment_average_frequency <- renderPlot({

output$segment_average_monetary <- renderPlot({

data <-
data <-
prep_segment() %>%
group_by(segment) %>%
select(segment, amount) %>%
summarize(median(amount)) %>%
rename(segment = segment, avg_monetary = `median(amount)`) %>%
arrange(avg_monetary)
arrange(avg_monetary)

n_fill <- nrow(data)

Expand All @@ -230,4 +233,4 @@ output$segment_average_monetary <- renderPlot({
plot.title = element_text(hjust = 0.5)
)

})
})

0 comments on commit 40edf0f

Please sign in to comment.