简体   繁体   English

使用tcltk软件包制作简单的R GUI

[英]Making simple R GUI with tcltk package

I'm trying to make very simple GUI for my script. 我正在尝试为我的脚本制作非常简单的GUI。 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是数据帧,我想绘制一列作为时间,并使用简单的GUI选择下一列/上一列。

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调用具有不同ifplot

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

Are you particularly attached to the idea of using tcltk? 您是否特别喜欢使用tcltk的想法? I've been working on something similar using the gWidgets package and have had some success. 我一直在使用gWidgets软件包进行类似的工作,并取得了一些成功。 According to it's CRAN site, "gWidgets provides a toolkit-independent API for building interactive GUIs". 据其CRAN网站称,“ gWidgets提供了独立于工具包的API,用于构建交互式GUI”。 This package uses tcltk or GTK2 and I've been using the GTK2 portion. 该软件包使用tcltk或GTK2,而我一直在使用GTK2部分。 Here's a quick example of a GUI with a spinbutton for changing i . 这是带有用于更改i的旋转按钮的GUI的快速示例。 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. 我还为您的函数添加了一些奇特之处,因为您提到要绘制时间序列,因此我将x轴定为时间。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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