Shiny app works locally, but not when deployed to shinyapps

Hi,

I have a shiny app, which uses the rhandsontable package. It works fine when I run the app on my local machine with RStudio. However, when I deploy it to shinyapps, it behaves very strangely. When I update fields in the table, it starts blinking and iterating between old and new values.

How can it be different locally and on shinyapps, and what can I do to fix this?

Many thanks,

Here is the application on shinyapps . https://oldmortality.shinyapps.io/hands6/

and here is the source:

library(shiny)
library(rhandsontable)
library(ggplot2)


# Define UI for application that draws a histogram
ui <- fluidPage(
  
  # Application title
  titlePanel(""),
  
  sidebarLayout(
    sidebarPanel(
      
    ),
    
    # Show a plot of the generated distribution
    mainPanel(
      rHandsontableOutput("hot") 
    )
  )
)


server <- function(input, output) {
  
  output$hot <- renderRHandsontable({
    if (is.null(input$hot)) {
      DF = data.frame(height=c(1750,rep(NA,9)))
    } else {
      DF = hot_to_r(input$hot)
    }
    rhandsontable(DF)  
  })
  
   
}

# Run the application 
shinyApp(ui = ui, server = server)

Hi @OldMortality

I believe rhandsontable is still experimental when used within a shinyapp. (See at bottom of description http://jrowen.github.io/rhandsontable/#shiny )

I looked as some of their posted apps, and your example looks the same as theirs.

I think this means an issue should be posted on the rhandsontable, especially if only the interaction of the widget is behaving improperly.

rhandsontable link: https://github.com/jrowen/rhandsontable/issues

Best,
Barret

1 Like

Thank you for the response to my post. Before posting, I had been in touch with the owner of rhandsontable. He says he cannot recreate the problem, and that the link I sent (to shinyapps) works fine for him.

It is strange, though, that it works locally (when deployed from RStudio) and not when deployed through shinyapps, and this does hint, I would say, at a problem with shinyapps.

Either way, it is something I cannot fix. Can you tell me, is there an alternative to rhandsontable?

Many thanks,

Michel

I see some javascript alternatives such as jqGrid or backgridjs, but I do not see any R packages that have converted them into htmlwidgets.

I originally did not see your flickering behavior in shinyapps.io, rather I couldn't save any value from the cell. Once I would hit enter, the value would disappear.

However, trying your shinyapp this morning (Mac Chrome and Firefox) it looks like it's working as expected.

Could you check again, please? I hope the issues on shinyapps.io were just passing false positives.

- Barret

Here is what I see on shinyapps and locally, with Rstudio.

shinyapps: https://youtu.be/hpOXsxDYwhw
rstudio local: https://youtu.be/Cf3aCW-CHsc

I couldn't figure out how to upload files on this forum, so I have used
youtube.

The rstudio one works as expected. The shinyapps one has bizarre
behaviour: values in cells disappear and come back.
It doesn't really matter which browser or OS I use. I get this on
mac,ubuntu, windows, with chrome, firefox, opera, explorer,
safari. Very strange, I think, how the initial table takes 3 steps to
settle: First we see 1750.00, then it changes to 1750 , and finally the
table narrows. I think this may happen locally as well, but it may be
too quick to see it properly.

All I want is a shiny app, with a table where I can enter some data, and
then -in this same app- a live histogram of the data. Surely that is
possible?

Thank you again,

Michel

Hi Michael,

Thank you for the video. It clearly shows what you are experiencing.

I'm still guessing this is a race case situation in how rhandsontable is implemented to work with shiny and shinyapps.io has a naturally built in delay between the UI information and the Server information. You are also entering the information quickly enough to be caught by the race case.


Don't want to leave you high and dry, so I've made a small shiny app that allows you to enter numeric values (one per line) and it will convert it to a histogram on the right.

Not as fancy, but it gets the job done.

Best,
Barret

library(ggplot2)
library(shiny)

shinyApp(
  fluidPage(
    fluidRow(
      column(
        4,
        textAreaInput(
          "textArea", "Enter data:", 
          width = "100%", height = "500px",
          value = paste0(sample(1:10, 10, replace = TRUE), collapse = "\n")
        )
      ),
      column(
        8,
        plotOutput("plot", height = "600px")
      )
    )
  ),
  function(input, output) {
    output$plot <- renderPlot({
      # convert input to numeric values
      x <- as.numeric(strsplit(input$textArea, "\\n")[[1]])
      validate(
        need(x, "Enter data into the text area"),
        need(length(x) > 1, "Enter at least two rows of data into the text area")
      )
      dt <- data.frame(x = x)
      ggplot(dt, aes(x)) + 
        geom_histogram()
    })
  }
)

Hi Barret,

I think you are right about the race. But I can't really present my
students with an application, which only works if you type slowly.

Good idea, a textarea is the way to go. Simple, and it works.

Many thanks,

Michel