Open a file for editing and saving using shiny

I can upload a into RStudio server using shiny.  However, I cannot open the file for editing and saving for processing by the R code.  Apparently, the randsontable library function ransdontable() takes as input a dataframe.  I am using the code below: DF = as.data.frame(read.delim(inFile$datapath))
    rhandsontable(DF, width = 550, height = 300)

but I get the message:

Warning: Error in as.data.frame.default: cannot coerce class "c("rhandsontable", "htmlwidget")" to a data.frame

Is there a solution for this, or is there any other way to open and edit file using shiny?

EDIT:
My code was completely wrong. If anyone wants to find more about the R rhandsontable, please post a question. I will be happy to help.
sunseAsked:
Who is Participating?
 
sunseConnect With a Mentor Author Commented:
This is an excellent implementation of rhandsone table from the gitHub.  Hope it will help.

library(shiny)
library(rhandsontable)

ui <- fluidPage(
  titlePanel("Handsontable"),
  titlePanel("Edit data file"),
  
  sidebarLayout(
    sidebarPanel(
      helpText("Changes to the table will be automatically saved to the source file"),
      actionButton("saveBtn", "Save"),
      helpText("Handsontable demo output. Column add/delete does work ",
               "for tables with defined column properties, including type."),
      radioButtons("useType", "Use Data Types", c("TRUE", "FALSE"))
    ),
    mainPanel(
      rHandsontableOutput("hot", width = 1500)
    )
  )
)

server <- function(input, output){
  
  fname = tempfile(fileext = ".tsv")
  observe({
    input$saveBtn
    hot = isolate(input$hot)
    if (!is.null(hot)) {
      write.table(hot_to_r(input$hot), fname)
      print(fname)
    }
    
  })
  
  output$hot = renderRHandsontable({
    if (!is.null(input$hot)) {
      DF = hot_to_r(input$hot)
    } else {
      DF = read.table("DataFile.tsv", sep = '\t', stringsAsFactors = FALSE)
    }
    
    rhandsontable(DF) %>%
      hot_table(highlightCol = TRUE, highlightRow = TRUE)
  })
  values <- reactiveValues()
  data = reactive({
    if (!is.null(input$hot)) {
      DF = hot_to_r(input$hot)
    } else {
      if (is.null(values[["DF"]]))
        DF = data.frame(val = 1:10, bool = TRUE, nm = LETTERS[1:10],
                        dt = seq(from = Sys.Date(), by = "days", length.out = 10),
                        stringsAsFactors = F)
      else
        DF = values[["DF"]] 
        DF = read.csv("glycoPipe_PARAMS_TEMPLATE.tsv", stringsAsFactors = FALSE)
        
    }
    
    values[["DF"]] = DF
    DF
  })
  
  output$hot <- renderRHandsontable({
    DF = data()
    if (!is.null(DF))
      rhandsontable(DF, useTypes = as.logical(input$useType), stretchH = "all")
  })
  
}

shinyApp(ui = ui, server = server)

Open in new window

0
 
sunseAuthor Commented:
The question has been updated with a solution to the problem.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.