Swechhya / excelR

An Interface to 'jExcel.js' Library
https://swechhya.github.io/excelR/
Other
152 stars 19 forks source link

Input object not available on initial render #112

Open lanceupton opened 1 year ago

lanceupton commented 1 year ago

Description

The input object corresponding to an excelOutput is not available after the initial render of the table, and before making any modifications to the table, or invalidating. It's almost like the input isn't binded until the output is invalidated at least once.

To Reproduce

In the included reprex:

  1. Click the Invalidate Input button to invalidate the excelOutput block.
  2. Observe that, as expected, the excelOutput renders.
  3. Observe that, unexpectedly, the datatableOutput (which simply conducts the input object from the excelTable), does not render. This is a side effect of the input object not being available.
  4. Click the Invalidate Input button to invalidate the excelOutput block again.
  5. Observe that, as expected, both outputs render.

Reprex


library(shiny)
library(excelR)

shinyApp(
  ui = fluidPage(
    tags$br(),
    fluidRow(column(width = 12, actionButton("btn", "Invalidate Input"))),
    tags$hr(),
    fluidRow(
      column(width = 6, excelOutput("tab1")),
      column(width = 6, dataTableOutput("tab2"))
    )
  ),
  server = function(input, output, session) {
    input_data <- eventReactive(input$btn, sample(1:50, 10))
    output$tab1 <- renderExcel(excelTable(data.frame(vals = input_data())))
    excel_data <- reactive(excel_to_R(input$tab1))
    output$tab2 <- renderDataTable(excel_data())
  }
)

Client Info

Session Info

R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux

Matrix products: default

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] excelR_0.4.0 shiny_1.7.3 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7        magrittr_2.0.1    xtable_1.8-4      R6_2.5.1          rlang_1.0.2       fastmap_1.1.0     tools_4.1.2       cli_3.3.0        
 [9] jquerylib_0.1.4   htmltools_0.5.2   ellipsis_0.3.2    yaml_2.2.1        digest_0.6.28     lifecycle_1.0.1   later_1.3.0       sass_0.4.0       
[17] htmlwidgets_1.5.4 promises_1.2.0.1  rsconnect_0.8.24  cachem_1.0.6      mime_0.12         compiler_4.1.2    bslib_0.3.1       jsonlite_1.7.2   
[25] httpuv_1.6.3      renv_0.15.5    
lanceupton commented 1 year ago

Fortunately, the workaround for this is simple. The conductor just needs to fallback to the source if the input object isn't available. Others experiencing this issue might consider using the following:

excel_data <- reactive(if (!is.null(input$tab1)) excel_to_R(input$tab1) else input_data())
AnthisKon commented 8 months ago

Facing similar issues, the table is not appearing when deploying to posit connect but works locally