Skip to content

Commit

Permalink
Switch from RJSONIO to jsonlite
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Jan 21, 2015
1 parent d994db9 commit 0755579
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Imports:
utils,
httpuv (>= 1.3.2),
mime (>= 0.1.3),
RJSONIO,
jsonlite (>= 0.9.14),
xtable,
digest,
htmltools (>= 0.2.6),
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,3 @@ import(htmltools)
import(httpuv)
import(mime)
import(xtable)
importFrom(RJSONIO,fromJSON)
2 changes: 1 addition & 1 deletion R/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ decodeMessage <- function(data) {
if (readInt(1) != 0x01020202L) {
# use native encoding for the message
nativeData <- iconv(rawToChar(data), 'UTF-8')
return(fromJSON(nativeData, asText=TRUE, simplify=FALSE))
return(jsonlite::fromJSON(nativeData, simplifyVector=FALSE))
}

i <- 5
Expand Down
6 changes: 3 additions & 3 deletions R/shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ NULL
#' @aliases shiny
#' @docType package
#' @import htmltools httpuv xtable digest R6 mime
#' @importFrom RJSONIO fromJSON
NULL


Expand Down Expand Up @@ -80,7 +79,8 @@ createUniqueId <- function(bytes, prefix = "", suffix = "") {
}

toJSON <- function(x, ..., digits = getOption("shiny.json.digits", 16)) {
RJSONIO::toJSON(x, digits = digits, ...)
jsonlite::toJSON(x, dataframe = "columns", null = "null", na = "null",
auto_unbox = TRUE, digits = digits, use_signif = TRUE, ...)
}

# Call the workerId func with no args to get the worker id, and with an arg to
Expand Down Expand Up @@ -301,7 +301,7 @@ ShinySession <- R6Class(

if (!is.null(websocket$request$HTTP_SHINY_SERVER_CREDENTIALS)) {
try({
creds <- fromJSON(websocket$request$HTTP_SHINY_SERVER_CREDENTIALS)
creds <- jsonlite::fromJSON(websocket$request$HTTP_SHINY_SERVER_CREDENTIALS)
session$user <<- creds$user
session$groups <<- creds$groups
}, silent=FALSE)
Expand Down
2 changes: 1 addition & 1 deletion R/update-input.R
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ updateSelectizeInput <- function(session, inputId, label = NULL, choices = NULL,
selectizeJSON <- function(data, req) {
query <- parseQueryString(req$QUERY_STRING)
# extract the query variables, conjunction (and/or), search string, maximum options
var <- unlist(fromJSON(query$field, asText = TRUE))
var <- unlist(jsonlite::fromJSON(query$field))
cjn <- if (query$conju == 'and') all else any
# all keywords in lower-case, for case-insensitive matching
key <- unique(strsplit(tolower(query$query), '\\s+')[[1]])
Expand Down
5 changes: 0 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -691,11 +691,6 @@ dataTablesJSON <- function(data, req) {
for (j in seq_len(ncol(fdata))[k]) fdata[, j] <- htmlEscape(fdata[, j])
}
}
# WAT: toJSON(list(x = matrix(nrow = 0, ncol = 1))) => {"x": } (#299)
if (nrow(fdata) == 0) fdata <- list()
# WAT: toJSON(list(x = matrix(1:2))) => {x: [ [1], [2] ]}, however,
# toJSON(list(x = matrix(1))) => {x: [ 1 ]} (loss of dimension, #429)
if (length(fdata) && all(dim(fdata) == 1)) fdata <- list(list(fdata[1, 1]))

res <- toJSON(list(
draw = as.integer(q$draw),
Expand Down
10 changes: 5 additions & 5 deletions inst/tests/test-input-handler.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test_that("Date converts to date", {
x <- "2013/01/01"
class(x) <- "shiny.date"
handler <- inputHandlers$get('shiny.date')
expect_identical(
expect_identical(
handler(x), as.Date(unclass(x))
)
})
Expand All @@ -24,7 +24,7 @@ test_that("List of dates converts to vector", {
x <- list("2013/01/01", "2014/01/01")
class(x) <- "shiny.date"
handler <- inputHandlers$get('shiny.date')
expect_identical(
expect_identical(
handler(x), as.Date(unlist(x))
)
})
Expand All @@ -41,7 +41,7 @@ test_that("Matrix converts list of lists to matrix", {
test_that("Nulls are not converted to NAs in parsing", {
msg <- charToRaw("{\"method\":\"init\",\"data\":{\"obs\":500,\"nullObs\":null}}")
expect_identical(
decodeMessage(msg),
list(method="init", data=list(obs=500, nullObs=NULL))
decodeMessage(msg),
list(method="init", data=list(obs=500L, nullObs=NULL))
)
})
})

0 comments on commit 0755579

Please sign in to comment.