Skip to content

Commit

Permalink
Adding stateSave to Pivot and updating View for stateSave (see rstudi…
Browse files Browse the repository at this point in the history
  • Loading branch information
vnijs committed Aug 26, 2015
1 parent 1abf145 commit 03c3f4e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 22 deletions.
20 changes: 11 additions & 9 deletions R/pivotr.R
Original file line number Diff line number Diff line change
Expand Up @@ -264,21 +264,23 @@ make_dt <- function(pvt,

dt_tab <- tab %>%
DT::datatable(container = sketch, rownames = FALSE,
filter = list(position = "top", clear = FALSE, plain = TRUE),
filter = list(position = "top"),
# filter = list(position = "top", clear = FALSE, plain = TRUE),
style = ifelse(pvt$shiny, "bootstrap", "default"),
# style = "bootstrap",
options = list(
# stateSave = TRUE,
search = list(regex = TRUE),
# search = list(search = search),
# searchCols = searchCols,
# order = order,
# search = list(regex = TRUE),

stateSave = TRUE,
search = list(search = search),
searchCols = searchCols,
order = order,

processing = FALSE,
pageLength = 10,
lengthMenu = list(c(10, 25, 50, -1), c("10","25","50","All"))
)
# , callback = DT::JS("$('a#refresh_radiant').on('click', function() { table.state.clear(); });
# $('input#uploadState').on('click', function() { table.state.clear(); });")
, callback = DT::JS("$('a#refresh_radiant').on('click', function() { table.state.clear(); });
$('input#uploadState').on('click', function() { table.state.clear(); });")
) %>% DT::formatStyle(., cvars, color = "white", backgroundColor = "grey") %>%
{if ("Total" %in% cn) DT::formatStyle(., "Total", fontWeight = "bold") else .}

Expand Down
2 changes: 2 additions & 0 deletions inst/base/test_code/gather_.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

select_(iris, .dots = setdiff(colnames(iris), c("Petal.Length", "Petal.Width")))
51 changes: 42 additions & 9 deletions inst/base/tools/data/pivotr_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@

pvt_normalize <- c("None" = "None", "Row" = "row", "Column" = "column",
"Total" = "total")
# pvt_perc <- c("Percentage" = "perc")
pvt_format <- c("None" = "none", "Color bar" = "color_bar", "Heat map" = "heat")
pvt_type <- c("Dodge" = "dodge","Fill" = "fill")

## UI-elements for pivotr
output$ui_pvt_cvars <- renderUI({
vars <- groupable_vars()
if (not_available(vars)) return()

isolate({
## keep the same categorical-variables 'active' if possible
sel <-
if(available(input$pvt_cvars) && all(input$pvt_cvars %in% vars))
input$pvt_cvars
else
state_multiple("pvt_cvars",vars, "")
})

selectizeInput("pvt_cvars", label = "Categorical variables:", choices = vars,
selected = state_multiple("pvt_cvars",vars, ""), multiple = TRUE,
# selected = state_multiple("pvt_cvars",vars, ""),
selected = sel,
multiple = TRUE,
options = list(placeholder = 'Select categorical variables',
plugins = list('remove_button', 'drag_drop'))
)
Expand Down Expand Up @@ -127,19 +138,32 @@ pvt_plot_inputs <- reactive({
})
})

observeEvent(input$pivotr_search_columns, {
isolate({
r_state$pivotr_search_columns <<- input$pivotr_search_columns
})
})

observeEvent(input$pivotr_state, {
isolate({
r_state$pivotr_state <<- input$pivotr_state
})
})

output$pivotr <- DT::renderDataTable({
pvt <- .pivotr()
if (is.null(pvt)) return()
pvt$shiny <- TRUE

# search <- r_state$pivotr_state$search$search
# if (is.null(search)) search <- ""
# searchCols <- lapply(r_state$pivotr_search_columns, function(x) list(search = x))
# order <- r_state$pivotr_state$order
# make_dt(pvt, format = input$pvt_format, perc = input$pvt_perc)

search <- r_state$pivotr_state$search$search
if (is.null(search)) search <- ""
searchCols <- lapply(r_state$pivotr_search_columns, function(x) list(search = x))
order <- r_state$pivotr_state$order
make_dt(pvt, format = input$pvt_format, perc = input$pvt_perc,
search = search, searchCols = searchCols, order = order)

make_dt(pvt, format = input$pvt_format, perc = input$pvt_perc)
# make_dt(pvt, format = input$pvt_format, perc = input$pvt_perc,
# search = search, searchCols = searchCols, order = order)
})

output$pivotr_chi2 <- renderPrint({
Expand Down Expand Up @@ -210,6 +234,11 @@ observeEvent(input$pivotr_rows_all, {

.plot_pivot <- reactive({
pvt <- .pivotr()


# isolate({


if (is.null(pvt)) return(invisible())
if (!is_empty(input$pvt_tab, FALSE))
pvt <- pvt_sorter(pvt, rows = r_data$pvt_rows)
Expand All @@ -218,6 +247,10 @@ observeEvent(input$pivotr_rows_all, {
# sshhr( do.call(pivotr, pvt_inputs()) )
pvt_plot_inputs() %>% { .$shiny <- TRUE; . } %>%
{ do.call(plot, c(list(x = pvt), .)) }

# })


})

output$plot_pivot <- renderPlot({
Expand Down
15 changes: 14 additions & 1 deletion inst/base/tools/data/view.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ my_dataTablesFilter = function(data, req) {
## to implement
}

observeEvent(input$dataviewer_search_columns, {
isolate({
r_state$dataviewer_search_columns <<- input$dataviewer_search_columns
})
})

observeEvent(input$dataviewer_state, {
isolate({
r_state$dataviewer_state <<- input$dataviewer_state
})
})

output$dataviewer <- DT::renderDataTable({

if (not_available(input$view_vars)) return()
Expand All @@ -36,7 +48,8 @@ output$dataviewer <- DT::renderDataTable({
if (is.null(search)) search <- ""

if (nrow(dat) > 100000) filt <- 'none'
else filt <- list(position = "top", clear = FALSE, plain = TRUE)
else filt <- list(position = "top")
# else filt <- list(position = "top", clear = FALSE, plain = TRUE)
# action = DT::dataTableAjax(session, dat, rownames = FALSE, filter = my_dataTablesFilter)
DT::datatable(dat, filter = filt,
rownames = FALSE, style = "bootstrap", escape = FALSE,
Expand Down
3 changes: 0 additions & 3 deletions radiant.sublime-project
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
{
"path": "/Users/vnijs/Desktop/GitHub/radiant_gh-pages"
},
{
"path": "/Users/vnijs/Desktop/GitHub/dt_state"
},
{
"path": "/Users/vnijs/Dropbox/TODO"
}
Expand Down

0 comments on commit 03c3f4e

Please sign in to comment.