session doesn't restart (shinysky problem?)

55 views
Skip to first unread message

Norman Packard

unread,
Oct 28, 2016, 11:50:43 PM10/28/16
to Shiny - Web Framework for R

I have a situation where reloading the web page does not start a new R session.
ui.R and server.R for a more or less minimal example are given below.
The shiny app is supposed to build a matrix row by row with each row input using 'Handsontable' from shinysky.
when the page is reloaded, the previous matrix values are still there, from which I infer that the R session has persisted.
Naturally, if I restart the server, a new R session is created.

I started having this problem when using shinysky package, so might be a problem there...

In a related post, Joe Cheng suggested SHINY_LOG_LEVEL=TRACE before starting the server.  The resulting output is attached.

Thanks for any help!!!

 

ui.R:

library(shiny)                                                                                                                                              

library(shinyBS)                                                                                                                                            

library(shinysky)                                                                                                                                           

                                                                                                                                                            

shinyUI (                                                                                                                                                   

    fluidPage(                                                                                                                                              

        p(HTML("<A HREF=\"javascript:history.go(0)\">Reset this page</A>")),                                                                                

        hr(),                                                                                                                                               

        bsModal("expDefModal","Current experimental design",'viewDef',size="large",dataTableOutput('expDefData')),                                          

        p('Enter variable name, followed by values:'),                                                                                                      

        hotable("expDefIn"),                                                                                                                                

        actionButton('addDef',"Add this variable to exp definition",styleclass='primary'),                                                                  

        actionButton('viewDef',"View exp definition",styleclass='primary')                                                                                  

    )                                                                                                                                                       

)                 


server.R:

library(shiny)                                                                                                                                              

library(shinyBS)                                                                                                                                            

library(shinysky)                                                                                                                                           

                                                                                                                                                            

                                                                                                                                                            

shinyServer(function(input, output,session) {                                                                                                               

                                                                                                                                                            

    NexpDefCols = 12                                                                                                                                        

    curVarVals <<- reactive({           # this is actually a function!                                                                                      

        hot.to.df(input$expDefIn)  })                                                                                                                       

    nmsExpDef <<- c('Name........',paste0('V',1:(NexpDefCols-1)))                                                                                           

    tmp = rep(as.numeric(NA),NexpDefCols)                                                                                                                   

    expDef <<- matrix(tmp,nrow=1)                                                                                                                           

    colnames(expDef) <<- nmsExpDef                                                                                                                          

                                                                                                                                                            

    warning(paste("Should be starting new session at ",date()))                                                                                             

                                                                                                                                                            

    observeEvent(input$addDef,{                                                                                                                             

        isolate({                                                                                                                                           

            curVals = unlist(curVarVals())                                                                                                                  

            if(!exists('fullExpDef')){                                                                                                                      

                            fullExpDef <<- matrix(curVals,nrow=1)                                                                                           

                            colnames(fullExpDef) = nmsExpDef                                                                                                

            } else {                                                                                                                                        

                fullExpDef <<- rbind(fullExpDef,curVals)                                                                                                    

            }                                                                                                                                               

        })                                                                                                                                                  

    })                                                                                                                                                      

                                                                                                                                                            

    ## Hands on table input:                                                                                                                                

    output$expDefIn <- renderHotable({                                                                                                                      

        input$addDef                                                                                                                                        

        isolate({                                                                                                                                           

            tmp = rep(as.numeric(NA),NexpDefCols)                                                                                                           

            expDef <<- matrix(tmp,nrow=1)              

            colnames(expDef) <<- nmsExpDef                                                                                                                  

            names(expDef) = nmsExpDef                                                                                                                       

            return(expDef)                                                                                                                                  

        })                                                                                                                                                  

    }, readOnly = FALSE)                                                                                                                                    

                                                                                                                                                            

    ## for modal display:                                                                                                                                   

    output$expDefData = renderDataTable({                                                                                                                   

        input$addDef                                                                                                                                        

        isolate({                                                                                                                                           

            colnames(fullExpDef)=nmsExpDef                                                                                                                  

            return(fullExpDef)                                                                                                                              

        })                                                                                                                                                  

    })                                                                                                                                                      

})                                      



ServerTrace.rtf

Norman Packard

unread,
Nov 1, 2016, 1:07:35 AM11/1/16
to Shiny - Web Framework for R

An update:
This problem doesn't have anything to do with the shinysky package.
Below is an example that simply adds a line to a matrix every button push.
After page refresh, the old data is still there.

ui.R
shinyUI (
    fluidPage
(
        p
(HTML("<A HREF=\"javascript:history.go(0)\">Reset this page</A>")),
        hr
(),
        bsModal
("expDefModal","Current experimental design",'viewDef',size="large",dataTableOutput('expDefData')),

        actionButton
('addDef',"Add to exp definition",styleclass='primary'),
        actionButton
('viewDef',"View exp definition",styleclass='primary')
   
)
)


server.R


library
(shiny)
library
(shinyBS)

shinyServer
(function(input, output,session) {

   
NexpDefCols = 12

    nmsExpDef
<<- c('Name........',paste0('V',1:(NexpDefCols-1)))
    tmp
= rep(as.numeric(NA),NexpDefCols)
    expDef
<<- matrix(tmp,nrow=1)
    colnames
(expDef) <<- nmsExpDef

    warning
(paste("Should be starting new session at ",date()))

    observeEvent
(input$addDef,{
        isolate
({

            curVals
= 1:NexpDefCols

           
if(!exists('fullExpDef')){
                            fullExpDef
<<- matrix(curVals,nrow=1)
                            colnames
(fullExpDef) = nmsExpDef
           
} else {
                fullExpDef
<<- rbind(fullExpDef,curVals)
           
}
       
})
   
})



   
## for modal display:
Reply all
Reply to author
Forward
0 new messages