简体   繁体   中英

Making simple R GUI with tcltk package

I'm trying to make very simple GUI for my script. In nutshell problem looks like that :

dataset is dataframe, I would like to plot one column as the time and use simple GUI for choosing next/previus column.

dataset <-data.frame(rnorm(10), rnorm(10), rnorm(10))

columnPlot <- function(dataset, i){

plot(dataset[, i])

}

how to use tcltk for calling fplot with different i 's ?

不是您要求的(与tcltk不相关),但是我建议您看看RStudio的新shiny包装。

Are you particularly attached to the idea of using tcltk? I've been working on something similar using the gWidgets package and have had some success. According to it's CRAN site, "gWidgets provides a toolkit-independent API for building interactive GUIs". This package uses tcltk or GTK2 and I've been using the GTK2 portion. Here's a quick example of a GUI with a spinbutton for changing i . I also added a little fanciness to your function because you mentioned you would be plotting time series, so I made the x axis Time.

data<-data.frame(rnorm(11),rnorm(11),rnorm(11))

i = 1

fplot <- function(i, data = data){
  library(ggplot2)
  TimeStart <- as.Date('1/1/2012', format = '%m/%d/%Y')
  plotdat <- data.frame(Value = data[ ,i], Time = seq(TimeStart,TimeStart + nrow(data) - 1, by = 1))
  myplot <- ggplot(plotdat, aes(x = Time, y = Value))+
    geom_line()
  print(myplot)
}

library(gWidgets)
options(guiToolkit = 'RGtk2')

window <- gwindow ("Time Series Plots", visible = T)
notebook <- gnotebook (cont = window)
group1 <- ggroup(cont = notebook, label = "Choose i", horizontal=F)
ichooser <- gspinbutton(cont = group1, from = 1, to = ncol(data), by = 1, value = i, handler = function(h,...){
  i <<- svalue(h$obj)})
plotbutton <- gbutton('Plot', cont = group1, handler=function(h,...){
  fplot(i, data)})
graphicspane1 <- ggraphics(cont = group1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM