upload *.RData file using shiny

498 views
Skip to first unread message

Dongwen Luo

unread,
May 23, 2014, 9:37:34 PM5/23/14
to shiny-...@googlegroups.com
Hi All,

See topic, Anybody could help me to make the following code working? Thanks in advance.

library(shiny)
runApp(list(ui = fluidPage(
  sidebarLayout(
    sidebarPanel(
     h4("Uploading Files"),
     fileInput('f1', 'Choose a RData File', accept=c('.RData'))
    ),
    mainPanel(
    "Data",
     h4("Data Information"),
     verbatimTextOutput("datastr")
    )
  )
),
server = function(input, output) {
  dataInput <- reactive({
    sessionEnvir <- sys.frame()
    if (!is.null(input$f1)) load(input$f1$datapath, sessionEnvir)
  })
  output$datastr <- renderPrint({
    if (is.null(dataInput()))  return()  else str(dataInput())
  })
}
))

Saurabh Bhatt

unread,
May 26, 2014, 7:00:51 AM5/26/14
to shiny-...@googlegroups.com
Hi Dongwen,

Your code is working good. Can you tell me that what you need (variable values or the list of variables)? 
Since you are loading a .RData file which is showing the character values and these character values are the names of the variables present in that environment. 
Now if you want to see the values of the variable try this code.

library(shiny)
runApp(list(ui = fluidPage(
     sidebarLayout(
         sidebarPanel(
             h4("Uploading Files"),
             fileInput('f1', 'Choose a RData File', accept=c('.RData'))
         ),
         mainPanel(
            "Data",
            h4("Data Information"),
             verbatimTextOutput("datastr")
         )
     )
 ),
 server = function(input, output) {
     dataInput <- reactive({
         sessionEnvir <- sys.frame()
         if (!is.null(input$f1)) load(input$f1$datapath, sessionEnvir)
     })
     output$datastr <- renderPrint({
         if (is.null(dataInput())){return()} else{dataInput(); str(VariableName) }  # The variable VariableName should present in your .RData file as a character value
     })
 }
 ))
Reply all
Reply to author
Forward
0 new messages