If I have GUI as follows
how can I add a checkbox that when you click on it,it gives you different files, then when you click on that file it gives you the information you are looking for, instead of me browsing for a file how do i turn it to be a csv or xls file check box.
dlg <- aDialog(items=list(
  file=fileItem("", attr=list(
    filter=list("CSV or txt"=list(
      patterns=c("*.csv","*.txt")
      ),
                "All files" = list(patterns=c("*"))
                ))),
  header=trueFalseItem(TRUE, tooltip=paste("Variable onfirst line?")),
  fill=trueFalseItem(TRUE, tooltip="Fill unequal length rows if TRUE"),
  sep=stringItem("", tooltip="Field separator character"),

  ## our things
  assign.to=stringItem("shapefile", label="Assign to:"),
  output=tableItem(attr=list(size=c(500,500)), show_label=TRUE),
  file.type=stringItem("")
  ),
               title="Nova Shape It csv or txt file",
               help_string="click browse button to search for a file."
               )
view <- aGroup(aNotebook(
  aNotebookPage("file",
                separatorItem(),
                "ShapeHeader","sep",
                label="shapeit"),
  aNotebookPage("file",
                separatorItem(),
                "fill","sep",
                label="file",
                )
  ),
               aContainer("assign.to",
                          aFrame("output", label="Preview")
                          ),
               horizontal=TRUE))
dlg$read_file <- function(., file.type, output, assign.to, ...) {
  if(file.type != "") {
out <- try(do.call(sprintf("read.%s",file.type), list(...)), silent=TRUE)
    if(inherits(out, "try-error")) {
      cat("Error reading file of type,", file.type, "\n")
      out <- data.frame(nova="")
    }
  } else {
    out <- data.frame(nova="")
  }
  return(out)
}
dlg$model_value_changed <- function(.) {
  fname <- .$get_file()
  if(file.exists(fname)) {
    for(i in c("txt","csv")) {
      if(grepl(paste("\\.",i,sep=""), fname))
        .$set_file.type(c(txt="table",csv="csv")[i])
    }
  }
  switch(.$get_file.type(),
         "csv"={.$set_sep(","); .$set_quote('\"')},
         "table"={},
{}
         )
  .$set_output(.$do_call("read_file",.$to_R()))
}
dlg$OK_handler <- function(.) {
  out <- .$do_call("read_file",.$to_R())
  assign.to <- .$get_assign.to()
  if(exists(assign.to, envir=.GlobalEnv)) {
    if(!gconfirm(sprintf("Overwrite variable %s?", assign.to)))
      return()
  }
  assign(assign.to, out, envir=.GlobalEnv)
}

dlg$make_gui(gui_layout=view)


--
Leah Mathibela
mobile:078-3311-491
work:087-7545-997
www.nova.org.za

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to