newbie questions

378 views
Skip to first unread message

low yi xiang

unread,
May 28, 2013, 8:26:30 AM5/28/13
to shiny-...@googlegroups.com

hi, i have two questions, 

firstly, is it possible to store a data set within the server?

so this is my UI codes,

library(shiny)

shinyUI(pageWithSidebar(
  headerPanel("Uploading Files"),
  sidebarPanel(
    fileInput('file1', 'Choose CSV File',
              accept=c('text/csv', 'text/comma-separated-values,text/plain')),
    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'),
    br(),
    br(),
    
    textInput("data_column","Input the column you wish to check","type something!"),
    
    br(),
    br(),
    
    checkboxGroupInput("variables","Choose your column number",c("to be filled up"))
  ),
  

  
  # Show a tabset that includes a plot, summary, and table view
  # of the generated distribution
  mainPanel(
    tabsetPanel(
      tabPanel("Contents",tableOutput("contents")),
      tabPanel("Plot", plotOutput("plot")), 
      tabPanel("Summary", verbatimTextOutput("summary")), 
      tabPanel("Table", tableOutput("table")),
      tabPanel("Boxplot",plotOutput("boxplot")),
      tabPanel("Logic test",verbatimTextOutput("logic_test"))
    )
  )
))

while my server codes is

library(shiny)
library(datasets)

shinyServer(function(input, output) {
  output$contents <- renderTable({
    
    data_frame<-reactive({
      raw_data<-input$file1
      if(is.null(raw_data))
        return(NULL)
      data_frame<-read.csv(raw_data$datapath,header=input$header,sep=input$sep,quote=input$quote)
      
    })
    # input$file1 will be NULL initially. After the user selects and uploads a 
    # file, it will be a data frame with 'name', 'size', 'type', and 'datapath' 
    # columns. The 'datapath' column will contain the local filenames where the 
    # data can be found.
    
    inFile <- input$file1
    
    if (is.null(inFile))
      return(NULL)
    
    read.csv(inFile$datapath, header=input$header, sep=input$sep, quote=input$quote)
  })
  
  output$boxplot<-renderPlot({
    data_Column<-input$data_column
    boxplot(data_frame[,data_Column])
  })
})

so basically, what i am essentially trying to do is the user can input name in the textbox, and it returns a boxplot of that box. 

but i have no idea how i can preserve the data or to call it within the server once a person has uploaded his file. 

i am doing this to deduct outlier using boxplot for non programming users.

Secondly, 

is it possible to update the sidebar panel with my names of the data?

so that instead of input the text name in the edit text, when the user uploads a data set, he can just tick the boxes to generate the boxplot individually or against each other. 

please help. thank you. 

Joe Cheng

unread,
May 28, 2013, 9:48:23 PM5/28/13
to shiny-...@googlegroups.com
First a general hint: If you are defining a reactive() inside of a renderXXX() or inside of another reactive(), you are probably making a mistake. Reactives and render functions should always be defined separately and refer to each other by name.


Here's a rewrite of your server.R:


library(shiny)
library(datasets)

shinyServer(function(input, output, session) {

  data_frame<-reactive({
    raw_data<-input$file1
    if(is.null(raw_data))
      return(NULL)
    read.csv(raw_data$datapath,header=input$header,sep=input$sep,quote=input$quote)
  })

  output$contents <- renderTable({
    
    if (is.null(data_frame()))
      return(NULL)
    
    read.csv(data_frame(), header=input$header, sep=input$sep, quote=input$quote)
  })
  
  output$boxplot<-renderPlot({
    data_Column<-input$data_column
    boxplot(data_frame()[,data_Column])
  })

  observe({
    if (is.null(data_frame()))
      return()
    updateCheckboxGroupInput(session, "variables", choices=names(data_frame()))
  })
})



--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Message has been deleted

low yi xiang

unread,
May 29, 2013, 3:10:46 AM5/29/13
to shiny-...@googlegroups.com
Thank you, regarding observe, 

updatecheckboxGroupInput does not exist, and i tired to do something like

 observe({
    if (is.null(data_frame()))
      return()
    
    update(checkboxGroupInput("variables","Choose your column number",c("to be filled up")),checkboxGroupInput("variables","Choose your column number",choices=names(data_frame()) ))
  })

but it does not work,

also, if i have a data of size 28mb, i removed the data limit cap, if i read using R-studio directly there is no problem, but when i upload using the browser both my browser and r-studio crashes. is there anyway to bypass this?

sorry for the trouble.

Joe Cheng

unread,
May 29, 2013, 5:28:29 PM5/29/13
to shiny-...@googlegroups.com
Did you add the session parameter to the function(input, output) at the top of server.R?

No, it should be updateCheckboxGroupInput. If you don't have this function then you will need to upgrade to the latest Shiny:

if (!require('devtools'))
  install.packages('devtools')
install.packages('httpuv', repos=c(RStudio='http://rstudio.org/_packages', CRAN='http://cran.rstudio.com')
devtools::install_github('shiny', 'rstudio')

I don't know why you're getting the read.table error though. Can you print the value of raw_data$datapath right before calling read.csv and see if it's something unexpected?


On Tue, May 28, 2013 at 6:42 PM, low yi xiang <yxl...@gmail.com> wrote:
Thank, you, when running your server, i encounter the following errors

Listening on port 8100
Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
  'file' must be a character string or connection
Error in tag("input", list(...)) : 
  argument "session" is missing, with no default

also, it should be update(checkboxGroupInput) right? 

On Wednesday, May 29, 2013 5:48:23 AM UTC+8, Joe Cheng [RStudio] wrote:

low yi xiang

unread,
May 30, 2013, 1:44:19 AM5/30/13
to shiny-...@googlegroups.com
thank you for your reply, i have encounted the following error, is there a way to bypass this?

devtools::install_github('shiny', 'rstudio')
Installing github repo(s) shiny/master from rstudio
Error in function (type, msg, asError = TRUE)  : couldn't connect to host
> library(shiny)
> ?updateCheckGroupInput
No documentation for ‘updateCheckGroupInput’ in specified packages and libraries:
you could try ‘??updateCheckGroupInput


i manage to over come the problem by doing this to the server

data_frame<-reactive({
    raw_data<-input$file1
    if(is.null(raw_data))
      return(NULL)
    read.csv(raw_data$datapath,header=input$header,sep=input$sep,quote=input$quote)
  })
  
  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)
  })

and yes, i did add the session parameter on my server function, i copied the entire text and run it on my rstudio

lastly, is there a way to stop my R-studio from crashing if i am reading huge sets of data? (if i read it through R-studio is using the command is fine, its only when i tried to upload it becomes a problem) 
Reply all
Reply to author
Forward
0 new messages