Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Swechhya/excelR into changes-for-…
Browse files Browse the repository at this point in the history
…0.4-release
  • Loading branch information
Swechhya committed Mar 9, 2020
2 parents 4301a72 + 6ad8c3c commit cd9d272
Show file tree
Hide file tree
Showing 15 changed files with 332 additions and 202 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(excelTable)
export(excel_to_R)
export(getComments)
export(get_selected_data)
export(get_selected_data_boundary)
export(renderExcel)
export(setComments)
import(htmlwidgets)
Expand Down
7 changes: 6 additions & 1 deletion R/excel_to_R.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
#'}

excel_to_R <- function(excelObj) {
if (!is.null(excelObj) && !excelObj$forSelectedVals ) {
if (!is.null(excelObj)) {
if( excelObj$forSelectedVals )
{
excelObj = excelObj$fullData
}

data <- excelObj$data
colHeaders <- excelObj$colHeaders
colType <- excelObj$colType
Expand Down
34 changes: 31 additions & 3 deletions R/get_selected_data.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Get selected cells from excel table
#'
#' This function is used to the data selected in excel table
#' This function is used to get the data selected in excel table
#' @export
#' @param excelObj the json data retuned from excel table
#' @examples
Expand All @@ -11,7 +11,7 @@
#' ui = fluidPage(excelOutput("table")),
#' server = function(input, output, session) {
#' output$table <-
#' renderExcel(excelTable(data = head(iris)))
#' renderExcel(excelTable(data = head(iris), getSelectedData = TRUE))
#' observeEvent(input$table,{
#' print(get_selected_data(input$table))
#' })
Expand All @@ -21,7 +21,7 @@

get_selected_data<- function(excelObj) {
if (!is.null(excelObj) && excelObj$forSelectedVals) {
data <- excelObj$data
data <- excelObj$selectedData
dataOutput <- do.call(rbind.data.frame, data)
rownames(dataOutput) <- NULL
colnames(dataOutput) <- NULL
Expand All @@ -30,3 +30,31 @@ get_selected_data<- function(excelObj) {
}

}

#' Get selected cells boundary from excel table
#'
#' This function is used to the boundary points of data selected in excel table
#' @export
#' @param excelObj the json data retuned from excel table
#' @examples
#'if(interactive()){
#' library(shiny)
#' library(excelR)
#' shinyApp(
#' ui = fluidPage(excelOutput("table")),
#' server = function(input, output, session) {
#' output$table <-
#' renderExcel(excelTable(data = head(iris), getSelectedData = TRUE))
#' observeEvent(input$table,{
#' print(get_selected_data_boundary(input$table))
#' })
#' }
#' )
#'}
get_selected_data_boundary<- function(excelObj) {
if (!is.null(excelObj) && excelObj$forSelectedVals) {
boundaryIndex <- excelObj$selectedDataBoundary
boundaryCell = lapply(boundaryIndex, function(x){x+1})
return(boundaryCell)
}
}
8 changes: 6 additions & 2 deletions R/jexcel.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
#' @param digits number of decimal digits passed to \code{jsonlite::toJSON}. By default it is set to 4, use \code{NA} for max precision.
#' @param autoWidth a boolean value indicating should the width of the column be automatically adjusted. By default this value is set to TRUE.
#' The width value specified in 'columns' param will have higher precedence.
#' @param autoFill a boolen value indicating wheather the excel table fill the container. By default this value is set to false.
#' @param autoFill a boolen value indicating whether the excel table fill the container. By default this value is set to false.
#' The width value specified in 'columns' param will have highest precendence followed by autoWidth.
#' @param getSelectedData a boolean value indicating whether the there should be trigger for data selection or not.
#' By default this is set to false.
#' @param ... other jexcel parameters, e.g., updateTable
#' @import jsonlite
#' @import htmlwidgets
Expand Down Expand Up @@ -92,6 +94,7 @@ excelTable <-
digits = 4,
autoWidth = TRUE,
autoFill = FALSE,
getSelectedData = FALSE,
...
) {
# List of parameters to send to js
Expand Down Expand Up @@ -338,7 +341,8 @@ excelTable <-
"loadingSpin",
"showToolbar",
"autoWidth",
"autoFill"
"autoFill",
"getSelectedData"
)) {
argvalue <- get(arg)
if(!is.null(argvalue)) {
Expand Down
14 changes: 9 additions & 5 deletions docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion docs/reference/excelTable.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/get_selected_data.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,11 @@ library(excelR)
output$table <-
renderExcel(excelTable(data = head(iris)))
observeEvent(input$table,{
print(excel_to_R(input$table))
table_data <- excel_to_R(input$table)
if(!is.null(table_data)){
print(table_data)
}

})
}
)
Expand Down Expand Up @@ -402,7 +406,7 @@ shinyApp(

server = function(input, output, session) {

output$table <- renderExcel(excelTable(data = head(iris), allowComments = TRUE))
output$table <- renderExcel(excelTable(data = head(iris), getSelectedData = TRUE))

# Print the selected data in table
observeEvent(input$table,{
Expand Down
Loading

0 comments on commit cd9d272

Please sign in to comment.