Creating a simple R GUI with tcltk

I am trying to make a very simple graphical interface for my script. In a nutshell, the problem looks like this:

dataset is a dataframe, I would like to build one column as time and use a simple graphical interface to select the next / previus column.

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

columnPlot <- function(dataset, i){

plot(dataset[, i])

}

how to use tcltk to call fplot with different i ?

+4
source share
2 answers

Not what you requested (not tcltk ), but I would advise you to take a look at the new shiny package from RStudio.

+8
source

Are you especially attached to the idea of ​​using tcltk? I worked on something similar with the gWidgets package and had some success. According to this CRAN site, "gWidgets provides an API that is independent of the tools for building interactive graphical interfaces." This package uses tcltk or GTK2, and I used the GTK2 part. Here is a brief example of a GUI with a spinbat for changing i . I also added a bit of fantasy to your function because you mentioned that you are planning time series, so I made an x ​​axis.

 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) 
+3
source

Source: https://habr.com/ru/post/1444486/


All Articles