Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using renderHotable() within renderUI() #20

Open
DesmondCampbell opened this issue Oct 13, 2015 · 0 comments
Open

using renderHotable() within renderUI() #20

DesmondCampbell opened this issue Oct 13, 2015 · 0 comments

Comments

@DesmondCampbell
Copy link

I'm trying to create a renderUI() function that produces a UI that includes an editable table.
When I use renderTable() it is successful.
When I use renderHotable() it throws an error.
I printed out the functions that both render functions return.
They differ at least in the attributes / classes of the function.
Perhaps this is the source of the problem.
Below I give some sample code and output for both scenarios.

regards
Desmond

renderHotable version

output$reportPed <- renderUI({
    fnRep("renderUI() BEGIN")

    LL <- list()
...
    dfPed <- data.frame(a=1:2,b=3:4)
    fnStr(dfPed)
    fnRender <- renderHotable( expr={ dfPed }, readOnly=F )
    fnStr(fnRender)
    print(fnRender)
    LL[[ length(LL) + 1 ]] <- fnRender

    fnStr(LL)
    fnRep("renderUI() END")
    return(LL)
})

throws an error and produces the following

VALUE: dfPed = 'data.frame': 2 obs. of 2 variables:
$ a: int 1 2
$ b: int 3 4

VALUE: fnRender = function ()
function ()
{
df <- func()
if (is.null(df)) {
return()
}
if (nrow(df) == 0) {
return()
}
json <- NULL
json$colHeaders <- colnames(df)
columns <- NULL
types <- sapply(df, typeof)
l <- length(types)
readOnly <- rep(readOnly, length.out = l)
for (i in 1:l) {
if (i == 1) {
columns[[i]] <- list(readOnly = readOnly[i])
}
else if (types[i] == "double") {
columns[[i]] <- list(type = "numeric", format = "0,0.00",
readOnly = readOnly[i])
}
else if (types[i] == "logical") {
columns[[i]] <- list(type = "checkbox", readOnly = readOnly[i])
}
else {
columns[[i]] <- list(readOnly = readOnly[i])
}
}
json$columns <- columns
json$data <- df
json
}
<environment: 0x00000000250e8008>

VALUE: LL = List of 4
$ :Classes 'html', 'character' atomic [1:1] Pedigree Diagram
.. ..- attr(, "html")= logi TRUE
$ :function (shinysession, name, ...)
..- attr(
, "class")= chr [1:2] "shiny.render.function" "function"
..- attr(, "outputFunc")=function (outputId, width = "100%", height = "400px", click = NULL, dblclick = NULL, hover = NULL, hoverDelay = NULL, hoverDelayType = NULL, brush = NULL, clickId = NULL, hoverId = NULL,
inline = FALSE)
$ :Classes 'html', 'character' atomic [1:1]


.. ..- attr(
, "html")= logi TRUE
$ :function ()
REPORT: renderUI() END

Error in as.character(x) :
cannot coerce type 'closure' to vector of type 'character'

it produces the following trace of the error

Enter a frame number, or 0 to exit

1: runApp(file.path("..", sAppDir))
2: shinyCallingHandlers(while (!.globals$stopped) {
serviceApp()
Sys.sleep(0.001)
})
3: withCallingHandlers(expr, error = function(e) {
handle <- getOption("shiny.error")
if (is.function(handle))
handle()
})
4: Sys.sleep(0.001)

whereas

renderTable version

output$reportPed <- renderUI({
    fnRep("renderUI() BEGIN")

    LL <- list()
...
    dfPed <- data.frame(a=1:2,b=3:4)
    fnStr(dfPed)
    fnRender <- renderTable( expr={ dfPed }, readOnly=F )
    print(fnRender)
    LL[[ length(LL) + 1 ]] <- fnRender

    fnStr(LL)
    fnRep("renderUI() END")
    return(LL)
})

runs cleanly and produces the following

VALUE: dfPed = 'data.frame': 2 obs. of 2 variables:
$ a: int 1 2
$ b: int 3 4

VALUE: fnRender = function ()

  • attr(*, "class")= chr [1:2] "shiny.render.function" "function"
  • attr(*, "outputFunc")=function (outputId)
    function ()
    {
    classNames <- getOption("shiny.table.class") %OR% "data table table-bordered table-condensed"
    data <- func()
    if (is.null(data) || identical(data, data.frame()))
    return("")
    return(paste(utils::capture.output(print(xtable(data, ...),
    type = "html", html.table.attributes = paste("class="",
    htmlEscape(classNames, TRUE), """, sep = ""), ...)),
    collapse = "\n"))
    }
    <environment: 0x00000000219b3fa0>
    attr(,"class")
    [1] "shiny.render.function" "function"
    attr(,"outputFunc")
    function (outputId)
    {
    div(id = outputId, class = "shiny-html-output")
    }
    <environment: namespace:shiny>

VALUE: LL = List of 4
$ :Classes 'html', 'character' atomic [1:1] Pedigree Diagram
.. ..- attr(, "html")= logi TRUE
$ :function (shinysession, name, ...)
..- attr(
, "class")= chr [1:2] "shiny.render.function" "function"
..- attr(, "outputFunc")=function (outputId, width = "100%", height = "400px", click = NULL, dblclick = NULL, hover = NULL, hoverDelay = NULL, hoverDelayType = NULL, brush = NULL, clickId = NULL, hoverId = NULL,
inline = FALSE)
$ :Classes 'html', 'character' atomic [1:1]


.. ..- attr(
, "html")= logi TRUE
$ :function ()
..- attr(, "class")= chr [1:2] "shiny.render.function" "function"
..- attr(
, "outputFunc")=function (outputId)
REPORT: renderUI() END

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant