Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions R/rpivotAddin.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
getDataFrames = function()
{
if ((length(ls()) == 0) | (length(sapply(.GlobalEnv, is.data.frame)) == 0) | (any(sapply(.GlobalEnv, is.data.frame))==F))
data(iris)
return(names(which(sapply(.GlobalEnv, is.data.frame))))
}

rpivotAddin <- function() {
library(shiny)
library(rpivotTable)
library(miniUI)
library(rstudioapi)

ui <- miniPage(

# css hack to provide space for a select input in the gadgetTitleBar
tags$head(tags$style(HTML("
.gadget-title .shiny-input-container {
position: relative;
height: 30px;
margin: 6px 10px 0;
z-index: 10;
}"))),

gadgetTitleBar("Pivot Table Gadget",
left=miniTitleBarButton("done", "Done", primary=T),
right=selectInput("dataset", NULL, choices = getDataFrames())),

miniContentPanel(
rpivotTableOutput("mypivot")
)
) # minipage

server <- function(input, output, session) {

output$mypivot <- renderRpivotTable({
rpivotTable(getSelectedDF())
})

observeEvent(input$done, {
stopApp(TRUE)
})

getSelectedDF <- reactive({
eval(parse(text = input$dataset))
})

} # server

runGadget(shinyApp(ui, server), viewer = paneViewer())
}
4 changes: 4 additions & 0 deletions inst/htmlwidgets/rpivotTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ HTMLWidgets.widget({
x.params.sorters = eval("("+x.params.sorters[0]+")")
}
}

if (typeof x.params.onRefresh != "undefined") {
x.params.onRefresh = x.params.onRefresh[0];
}

$('#'+el.id).pivotUI(
x.data, x.params, true
Expand Down
4 changes: 4 additions & 0 deletions inst/rstudio/addins.dcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Name: rpivotTable
Description: Pivot Table
Binding: rpivotAddin
Interactive: true