2012-08-06 3 views
0
require(tcltk) 
ttMain <- tktoplevel() 
tktitle(ttMain) <- "ttMain" 
launchDialog <- function() { 
    ReturnVal <- modalDialog("First Gene", "Enter A Gene Name", "") 
    if (ReturnVal == "ID_CANCEL") return() 
    tkmessageBox(title = "Heatmap", 
     message = paste("Hello, ", ReturnVal, ".", sep = "")) 
} 
launchDlg.button <- tkbutton(ttMain, text = "Launch Dialog", command = launchDialog) 
tkpack(launchDlg.button) 

. 필자는 pedM이라고 불리는 모든 데이터가 필요한 데이터 프레임을 가지고 있으며, ReturnVal은 해당 데이터 프레임 내의 열 이름 (특정 유전자)을 나타냅니다. 도와주세요.사용 tcltk 히트 맵 내가 히트 맵을 반환</strong><strong>메시지를 가지고 코드의 마지막 줄을 다시 할

제공 될 수있는 팁은 훌륭합니다. 미리 감사드립니다.

+0

어떤 언어입니까? 그것은 확실히 TCL처럼 _look_하지 않습니다 ... –

+0

죄송합니다, 분명히해야합니다. 이것은 Tcl/tk 패키지를 사용하는 R에 있습니다. –

+0

은 저에게'tkrplot'에 대한 직업처럼 보입니다. –

답변

0

다음은 도움이 될만한 예입니다. 귀하의 코드는 AFAIK가 존재하지 않는 modalDialog 함수를 사용합니다. 여기에 롤하는 방법의 예는 자신의

library(tcltk) 
library(tcltk2) 

tkinput <- function(parent, title, label, okButLabel="Ok", posx=NULL, posy=NULL) { 
    if(!require(tcltk2)) stop("This function requires the package tcltk2.") 
    if(!require(tcltk)) stop("This function requires the package tcltk.") 

    # param checks 
    if(!is.character(title)) stop("invalid title argument - character required.") 
    if(!is.character(label)) stop("invalid label argument - character required.") 

    # toplevel 
    tclServiceMode(FALSE) # don't display until complete 
    win <- tktoplevel(parent) 
    #win <- .Tk.subwin(parent) 
    tkwm.title(win, title) 
    tkwm.resizable(win, 0,0) 
    #tkconfigure(win, width=width, height=height) 

    # commands 
    okCommand <- function() if(!tclvalue(bookmVar)=="") tkdestroy(win) else tkfocus(te) 
    cancelCommand <- function() { 
    tclvalue(bookmVar) <- "" 
    tkdestroy(win) 
    } 
    tkwm.protocol(win, "WM_DELETE_WINDOW", cancelCommand) 

    # pack 
    f <- tk2frame(win) 
    w <- tk2label(f, text=label, justify="right") 
    tkpack(w, side="left", padx=5) 
    bookmVar <- tclVar("") 
    te <- tk2entry(f, textvariable=bookmVar, width=40) 
    tkpack(te, side="left", padx=5, fill="x", expand=1) 
    tkpack(f, pady=5) 
    f <- tk2frame(win) 
    w <- tk2button(f, text=okButLabel, command=okCommand) 
    tkpack(w, side="left", padx=5) 
    w <- tk2button(f, text="Cancel", command=cancelCommand) 
    tkpack(w, side="left", padx=5) 
    tkpack(f, pady=5) 

    # position 
    if(is.null(posx)) posx <- as.integer((as.integer(tkwinfo("screenwidth", win)) - as.integer(tkwinfo("width", win)))/2.) 
    if(is.null(posy)) posy <- as.integer((as.integer(tkwinfo("screenheight", win)) - as.integer(tkwinfo("height", win)))/2.) 
    geom <- sprintf("+%d+%d", posx, posy) 
    #print(geom) 
    tkwm.geometry(win, geom) 

    # run 
    tclServiceMode(TRUE) 
    ico <- tk2ico.load(file.path(R.home(), "bin", "R.exe"), res = "R") 
    tk2ico.set(win, ico) 
    tk2ico.destroy(ico) 
    tkfocus(te) 
    tkbind(win, "<Return>", okCommand) 
    tkbind(win, "<Escape>", cancelCommand) 
    tkwait.window(win) 
    tkfocus(parent) 
    return(tclvalue(bookmVar)) 
} 

대신 메시지 박스의 히트 맵을 플롯하려면이 코드는 히트 맵을 생산뿐만 아니라 오류를 제공

library(tkrplot) 

heat_example <- function() { 
    x <- as.matrix(mtcars) 
    rc <- rainbow(nrow(x), start=0, end=.3) 
    cc <- rainbow(ncol(x), start=0, end=.3) 
    hv <- heatmap(x, col = cm.colors(256), scale="column", 
     RowSideColors = rc, ColSideColors = cc, margins=c(5,10), 
     xlab = "specification variables", ylab= "Car Models", 
     main = "heatmap(<Mtcars data>, ..., scale = \"column\")") 
} 

launchDialog <- function() { 
    ReturnVal <- tkinput(parent=ttMain, title="First Gene", label="Enter A Gene Name") 
    if (ReturnVal == "") return() 

    hmwin <- tktoplevel(ttMain) 
    img <- tkrplot(hmwin, heat_example) 
    tkpack(img, hmwin) 
} 

ttMain <- tktoplevel() 
tktitle(ttMain) <- "ttMain" 
launchDlg.button <- tkbutton(ttMain, text = "Launch Dialog", command = launchDialog) 
tkpack(launchDlg.button, ttMain) 

tkrplot 기능을 사용할 수 있습니다 메시지를 해결할 수 없습니다. 어쩌면 여기 다른 누군가가 문제를 찾을 수 있습니다.