How to make an uploaded data reactive ?

21 views
Skip to first unread message

Jules Octave

unread,
Aug 25, 2016, 4:58:51 PM8/25/16
to Shiny - Web Framework for R
Please i find it difficult to calculate the disimilarity matrix after uploadin a data . i think i first need to make it reactive that i don t know yet . Anyone help please.

the server code is 

shinyServer(function(input, output) {
  output$contents <- renderTable({
    inFile <- input$file1
    
    if (is.null(inFile))
      return(NULL)
    
  read.csv(inFile$datapath, header=input$header, sep=input$sep, quote=input$quote)
  })
  
  output$view <- renderTable({
    #summary()
  })
  
  
})


and the ui code is 

shinyUI(pageWithSidebar(
  headerPanel("Solving the quadratic assignment problem using seriation"),
  sidebarPanel(
    fileInput('file1', 'Choose CSV File',
              accept=c('text/csv', 'text/comma-separated-values,text/plain', '.csv')),
    tags$hr(),
    checkboxInput('header', 'Header', TRUE),
    radioButtons('sep', 'Separator',
                 c(Comma=',',
                   Semicolon=';',
                   Tab='\t'),
                 'Comma'),
    radioButtons('quote', 'Quote',
                 c(None='',
                   'Double Quote'='"',
                   'Single Quote'="'"),
                 'Double Quote')
  ),
  mainPanel(
    h4("Data"),
    tableOutput('contents'),
    h4("Dissimilarity matrix"),
    tableOutput("view")
  )
))

i need to get the reactive data so as i can calculate the disimilarity .
Thanks for your time

Joe Cheng

unread,
Aug 25, 2016, 6:52:55 PM8/25/16
to Jules Octave, Shiny - Web Framework for R
You need to extract the data you want to use into a reactive expression. Like userdata, below:

shinyServer(function(input, output) {
  userdata <- reactive({
    inFile <- input$file1
    
    if (is.null(inFile))
      return(NULL)
    
    read.csv(inFile$datapath, header=input$header, sep=input$sep, quote=input$quote)
  })

  output$contents <- renderTable({
    userdata()
  })
  
  output$view <- renderTable({
    summary(userdata())  # or whatever
  })
})

You may want to watch the two parts of the Effective Reactive Programming tutorial here: https://www.rstudio.com/resources/webinars/shiny-developer-conference/

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/bbfc8200-a231-4f75-b89d-d0284af458ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages