7

How can I display a message box in R ?

I'm looking for something similar to msgbox in VBA, so I can for example alert the user about a problem.

Additionally I would like to allow some user interaction. So for example I could ask the user what day the program should use.

moodymudskipper
  • 46,417
  • 11
  • 121
  • 167
dekio
  • 810
  • 3
  • 16
  • 33
  • 1
    Can you ask your question so that it will be more specific so it doesn't get closed? That being said, are you looking for this? http://cran.r-project.org/web/packages/tcltk2/index.html – Roman Luštrik Nov 05 '13 at 17:23
  • 1
    Package svDialogs has some higher level functions that tap into tcltk mentioned by Roman and ialm. – Dieter Menne Nov 05 '13 at 17:30
  • Yes, it was exactly that what I was looking for. Sorry I didn't specify too much. I thought it was ok the way I wrote. I'll make sure that doesn't happen again – dekio Nov 06 '13 at 11:16
  • I think the question should be reopened, it has a lot of views and asks about a legit R feature, I reworded it and asked to reopen. – moodymudskipper May 16 '19 at 09:39

1 Answers1

18

What do you want to do exactly? Two things come to mind.

You can use the tcl/tk package in R to create a UI. See some examples with code from here: http://www.sciviews.org/_rgui/tcltk/. This package provides quick and easy functions to create message boxes, widgets, and other simple or complicated UIs. I created a point and click pipeline for producing plots in R using this package a couple years ago for users that were unfamiliar with R. I believe that this package is already installed with newer versions of R.

Here is a very simple example you can try:

require(tcltk)
msgBox <- tkmessageBox(title = "Title of message box",
                       message = "Hello, world!", icon = "info", type = "ok")

enter image description here

You can also create message boxes that accept inputs from the user that you can use later, etc. Check out the website I linked for a list of examples to get you started.

Next, we have the newer Shiny interface, which can ask for user input and produce output dynamically over the web, though it is a little more advanced. It provides a user interface through your browser through some simple R code, and the backend is created using R code as well. No javascript or html is required to get a simple set up going, but there is a slight learning curve for coding the Shiny app. You can easily create local Shiny apps by simply installing the shiny package on your local machine, but some set up is required to set up a server to deploy your R app outside of your local system. The RStudio team is offering free accounts on their servers if you want to deploy your R Shiny app over the web. Go to http://www.rstudio.com/shiny/ for some examples, and you can find tutorials at http://rstudio.github.io/shiny/tutorial/.

ialm
  • 8,510
  • 4
  • 36
  • 48
  • There seems to be a problem with `tkmessageBox`, I don't see any box (but there's the red button on RStudio that shows that something is runnin) – Julien Aug 14 '23 at 09:22