# Simple Dummy R GUI Generator

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Imagine you finish a dirty coding project and want to present to your boss who is not in a good mood (may not be occasionally), how are you going to start? Show him your hundreads of lines code, point to the lines, explain what the arguments and outputs are? No, it is not a smart way since you are supposed to introduce in a few short sentences. Generating a GUI is probably the quickest / easiest way of understanding what this code does. As the old saying goes: a picture is worth a thousand words, so in a same logic, **Quantitative Finance Collector**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**a GUI is worth n thousand words**.

However, generating GUI is by no means easy as I know the pain when creating the Matlab-GUI equity derivative calculator. It becomes even worse in R language, to be honest, I hate the graph plotting in R, terribly unflexible compared with in Matlab. Luckily I came across a good R GUI package named “

**fgui**“, it does as its description: Rapidly create a GUI interface for a function you created by automatically creating widgets for arguments of the function.

Very nice indeed, after playing for half an hour, it is simple to use, especially when what you need is just a basic GUI demonstrating to others a rough idea.

**One line code is enough**.

For a simple example, I create a European option pricer with Black Scholes formula,

EuropeanOption <- function (s, k, r, t, vol, CallOption) {

d1 <- (log(s/k)+(r+0.5*vol^2)*t)/(vol*sqrt(t))

d2 <- d1-vol*sqrt(t)

if (CallOption){

return (s*pnorm(d1)-k*exp(-r*t)*pnorm(d2))

} else {

return (k*exp(-r*t)*pnorm(-d2)-s*pnorm(-d1))

}

}

d1 <- (log(s/k)+(r+0.5*vol^2)*t)/(vol*sqrt(t))

d2 <- d1-vol*sqrt(t)

if (CallOption){

return (s*pnorm(d1)-k*exp(-r*t)*pnorm(d2))

} else {

return (k*exp(-r*t)*pnorm(-d2)-s*pnorm(-d1))

}

}

**then generating a GUI for this function is as simple as adding the following code**

res <- gui(EuropeanOption, argOption=list(CallOption=c("TRUE","FALSE")))

It returns a GUI looks like

where you are able to set inputs and get outputs. Nice. More advanced GUI is possible by adding more lines.

Interested readers shall download the package “

**fgui**” at http://cran.r-project.org/web/packages/fgui/index.html

Tags – r , gui

**Read the full post at Simple Dummy R GUI Generator**.

To

**leave a comment**for the author, please follow the link and comment on their blog:**Quantitative Finance Collector**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.