Title: | 'SciViews' - Standard Dialog Boxes for Windows, MacOS and Linuxes |
---|---|
Description: | Quickly construct standard dialog boxes for your GUI, including message boxes, input boxes, list, file or directory selection, ... In case R cannot display GUI dialog boxes, a simpler command line version of these interactive elements is also provided as fallback solution. |
Authors: | Philippe Grosjean [aut, cre] , Paul Hibbins [ctb] |
Maintainer: | Philippe Grosjean <[email protected]> |
License: | GPL-2 |
Version: | 1.1.0 |
Built: | 2024-12-25 02:55:49 UTC |
Source: | https://github.com/SciViews/svDialogs |
Select an existing directory, or create a new one.
dlg_dir(default = getwd(), title = "Choose a directory", ..., gui = .GUI) dlgDir(default = getwd(), title = "Choose a directory", ..., gui = .GUI) ## S3 method for class 'gui' dlg_dir(default = getwd(), title, ..., gui = .GUI) ## S3 method for class 'textCLI' dlg_dir(default = getwd(), title, ..., gui = .GUI) ## S3 method for class 'nativeGUI' dlg_dir( default = getwd(), title, rstudio = getOption("svDialogs.rstudio", TRUE), ..., gui = .GUI )
dlg_dir(default = getwd(), title = "Choose a directory", ..., gui = .GUI) dlgDir(default = getwd(), title = "Choose a directory", ..., gui = .GUI) ## S3 method for class 'gui' dlg_dir(default = getwd(), title, ..., gui = .GUI) ## S3 method for class 'textCLI' dlg_dir(default = getwd(), title, ..., gui = .GUI) ## S3 method for class 'nativeGUI' dlg_dir( default = getwd(), title, rstudio = getOption("svDialogs.rstudio", TRUE), ..., gui = .GUI )
default |
The path to the default directory that is proposed (e.g., current working directory). |
title |
A title to display on top of the dialog box. |
... |
Pass further arguments to methods. |
gui |
The 'gui' object concerned by this dialog box. |
rstudio |
Logical. Should 'RStudio' dialog boxes automatically be used
if available? If |
The modified 'gui' object is returned invisibly. Use its gui$res
component to get the returned directory (the string is empty when the user
cancelled the dialog box, see example).
## Not run: # A quick default directory changer setwd(dlg_dir(default = getwd())$res) ## End(Not run)
## Not run: # A quick default directory changer setwd(dlg_dir(default = getwd())$res) ## End(Not run)
A customizable form dialog box with checkboxes, entries, lists, etc.
dlg_form( form, title = "Fill the form", message = NULL, columns = 1, strip.type = TRUE, ..., gui = .GUI ) dlgForm( form, title = "Fill the form", message = NULL, columns = 1, strip.type = TRUE, ..., gui = .GUI ) ## S3 method for class 'gui' dlg_form( form, title = "Fill the form", message = NULL, columns = 1, strip.type = TRUE, ..., gui = .GUI ) ## S3 method for class 'textCLI' dlg_form( form, title = "Fill the form", message = NULL, columns = 1, strip.type = TRUE, ..., gui = .GUI ) ## S3 method for class 'nativeGUI' dlg_form( form, title = "Fill the form", message = NULL, columns = 1, strip.type = TRUE, ..., gui = .GUI )
dlg_form( form, title = "Fill the form", message = NULL, columns = 1, strip.type = TRUE, ..., gui = .GUI ) dlgForm( form, title = "Fill the form", message = NULL, columns = 1, strip.type = TRUE, ..., gui = .GUI ) ## S3 method for class 'gui' dlg_form( form, title = "Fill the form", message = NULL, columns = 1, strip.type = TRUE, ..., gui = .GUI ) ## S3 method for class 'textCLI' dlg_form( form, title = "Fill the form", message = NULL, columns = 1, strip.type = TRUE, ..., gui = .GUI ) ## S3 method for class 'nativeGUI' dlg_form( form, title = "Fill the form", message = NULL, columns = 1, strip.type = TRUE, ..., gui = .GUI )
form |
Named list of default values, or list of possible items. Names are the labels of corresponding entries in the dialog box, followed by an indicator of the type of entry to place in the dialog box (see details). |
title |
The title of the form. |
message |
An optional message to display in the dialog box. Use
|
columns |
Arrange the entries on this number of columns (by row). |
strip.type |
Do we strip the type from the names in results? |
... |
Pass further arguments to methods. |
gui |
The 'gui' object concerned by this dialog box. |
The form content is defined by a named list. Items are default values, or a list of possible items, e.g., for the combobox. Names are labels displayed in front of each field in the form. Follow them by a code that represents the type of entry you want to use:
:TXT
for simple (default) textual box,
:H
for hidden text (password),
:RO
for read-only text,
:NUM
for null of positive integers with up/down arrows,
:CHK
for checkbox: TRUE
or FALSE
,
:CB
for read-only combobox,
:CBE
for editable combobox,
:FL
to select one existing file,
:MFL
to select multiple existing files,
:SFL
to select or create one file,
:DIR
to select a directory,
:CDIR
to select or create a directory,
:FN
to select font and font size,
:DT
to enter a date,
:CLR' to enter a RGB color,
:BTN' to create a button that execute some code,
:LBL
to add a label.
For the moment, the form dialog box is only supported on Linux. You have to
install yad to get access to it. On Ubuntu, you do so by
sudo apt-get install yad
. For other system, look at the documentation.
The modified 'gui' object is returned invisibly. Use its gui$res
component to get the list of returned fields.
dlg_form()
can use strings with embedded quotes, but you have to
escape them (and need to double the backslash escape sign). Currently,
this is not done automatically, on the contrary to the other dlg_xxx()
functions!
## Not run: # Ask a series of items at once in a dialog box form <- list( "Name:TXT" = "John Smith", "Age:NUM" = 25, "Sex:CB" = c("male", "female"), "Married:CHK" = FALSE ) dlg_form(form, "My data")$res ## End(Not run)
## Not run: # Ask a series of items at once in a dialog box form <- list( "Name:TXT" = "John Smith", "Age:NUM" = 25, "Sex:CB" = c("male", "female"), "Married:CHK" = FALSE ) dlg_form(form, "My data")$res ## End(Not run)
Prompt for some data in a modal dialog box.
dlg_input(message = "Enter a value", default = "", ..., gui = .GUI) dlgInput(message = "Enter a value", default = "", ..., gui = .GUI) ## S3 method for class 'gui' dlg_input(message = "Enter a value", default = "", ..., gui = .GUI) ## S3 method for class 'textCLI' dlg_input(message = "Enter a value", default = "", ..., gui = .GUI) ## S3 method for class 'nativeGUI' dlg_input( message = "Enter a value", default = "", rstudio = getOption("svDialogs.rstudio", TRUE), ..., gui = .GUI )
dlg_input(message = "Enter a value", default = "", ..., gui = .GUI) dlgInput(message = "Enter a value", default = "", ..., gui = .GUI) ## S3 method for class 'gui' dlg_input(message = "Enter a value", default = "", ..., gui = .GUI) ## S3 method for class 'textCLI' dlg_input(message = "Enter a value", default = "", ..., gui = .GUI) ## S3 method for class 'nativeGUI' dlg_input( message = "Enter a value", default = "", rstudio = getOption("svDialogs.rstudio", TRUE), ..., gui = .GUI )
message |
The message to display in the dialog box. Use |
default |
The default value in the text box. Single string or |
... |
Pass further arguments to methods. |
gui |
The 'gui' object concerned by this dialog box. |
rstudio |
Logical. Should 'RStudio' dialog boxes automatically be used
if available? If |
The modified 'gui' object is returned invisibly. The text entered by
the user at the input box, or an empty string if the dialog box was cancelled
can be obtained from gui$res
(see example).
The 'RStudio' version of this dialog box does not allow for an empty
string. So, for better portability, try never to expect an empty string from
the user (the 'Cancel'
button is there to dismiss the dialog box).
On MacOS, single and double quotes are temporarily replaced by their slanted
versions (unicode characters u3032 and u2033, respectively) because the
command that triggers the dialog box does not allow quotes inside strings.
Regular quotes are reset on the output. This is the only hack we found that
was working. Better solutions are welcome!
dlg_list()
, dlg_form()
, dlg_message()
## Not run: # Ask something... user <- dlg_input("Who are you?", Sys.info()["user"])$res if (!length(user)) {# The user clicked the 'cancel' button cat("OK, you prefer to stay anonymous!\n") } else { cat("Hello", user, "\n") } ## End(Not run)
## Not run: # Ask something... user <- dlg_input("Who are you?", Sys.info()["user"])$res if (!length(user)) {# The user clicked the 'cancel' button cat("OK, you prefer to stay anonymous!\n") } else { cat("Hello", user, "\n") } ## End(Not run)
Display a list and allow user to select either one, or multiple items in that list.
dlg_list( choices, preselect = NULL, multiple = FALSE, title = NULL, ..., gui = .GUI ) dlgList( choices, preselect = NULL, multiple = FALSE, title = NULL, ..., gui = .GUI ) ## S3 method for class 'gui' dlg_list( choices, preselect = NULL, multiple = FALSE, title = NULL, ..., gui = .GUI ) ## S3 method for class 'textCLI' dlg_list( choices, preselect = NULL, multiple = FALSE, title = NULL, ..., gui = .GUI ) ## S3 method for class 'nativeGUI' dlg_list( choices, preselect = NULL, multiple = FALSE, title = NULL, rstudio = getOption("svDialogs.rstudio", TRUE), ..., gui = .GUI )
dlg_list( choices, preselect = NULL, multiple = FALSE, title = NULL, ..., gui = .GUI ) dlgList( choices, preselect = NULL, multiple = FALSE, title = NULL, ..., gui = .GUI ) ## S3 method for class 'gui' dlg_list( choices, preselect = NULL, multiple = FALSE, title = NULL, ..., gui = .GUI ) ## S3 method for class 'textCLI' dlg_list( choices, preselect = NULL, multiple = FALSE, title = NULL, ..., gui = .GUI ) ## S3 method for class 'nativeGUI' dlg_list( choices, preselect = NULL, multiple = FALSE, title = NULL, rstudio = getOption("svDialogs.rstudio", TRUE), ..., gui = .GUI )
choices |
The list of items. It is coerced to character strings. |
preselect |
A list of preselections, or |
multiple |
Is it a multiple selection dialog box? |
title |
The title of the dialog box, or |
... |
Pass further arguments to methods. |
gui |
The 'gui' object concerned by this dialog box. |
rstudio |
Logical. Should 'RStudio' dialog boxes automatically be used
if available? If |
The modified 'gui' object is returned invisibly. A list with selected
items, or a character vector of length 0 if the dialog box was cancelled is
available from gui$res
(see examples).
RStudio does not provide (yet) a graphical list selector (as of version
1.1.447). Consequently, a Tk version is used (if 'tcltk' is available) for
'RStudio Desktop' and a textual version at the R Console is used in the other
cases, for 'nativeGUI'
as a temporary workaround (should be implemented in
Shiny later on). Also note that the textual version only reports preselection
when multiple == TRUE
, and they are not used automatically if you do not
respecify them in your feedback (limitation of
utils::select.list(graphics = FALSE)
).
On MacOS, and outside of R(64).app, which has his own list selection dialog
box, single and double quotes are temporarily replaced by their slanted
versions (unicode characters u3032 and u2033, respectively) because the
command that triggers the dialog box does not allow quotes inside strings.
Regular quotes are reset on the output. This is the only hack we found that
was working. Better solutions are welcome, of course!
## Not run: # Select one or several months res <- dlg_list(month.name, multiple = TRUE)$res if (!length(res)) { cat("You cancelled the choice\n") } else { cat("You selected:\n") print(res) } ## End(Not run)
## Not run: # Select one or several months res <- dlg_list(month.name, multiple = TRUE)$res if (!length(res)) { cat("You cancelled the choice\n") } else { cat("You selected:\n") print(res) } ## End(Not run)
A message box with icon, text, and one to three buttons.
dlg_message( message, type = c("ok", "okcancel", "yesno", "yesnocancel"), ..., gui = .GUI ) dlgMessage( message, type = c("ok", "okcancel", "yesno", "yesnocancel"), ..., gui = .GUI ) msg_box(message) msgBox(message) ok_cancel_box(message) okCancelBox(message) ## S3 method for class 'gui' dlg_message( message, type = c("ok", "okcancel", "yesno", "yesnocancel"), ..., gui = .GUI ) ## S3 method for class 'textCLI' dlg_message( message, type = c("ok", "okcancel", "yesno", "yesnocancel"), ..., gui = .GUI ) ## S3 method for class 'nativeGUI' dlg_message( message, type = c("ok", "okcancel", "yesno", "yesnocancel"), rstudio = getOption("svDialogs.rstudio", TRUE), ..., gui = .GUI )
dlg_message( message, type = c("ok", "okcancel", "yesno", "yesnocancel"), ..., gui = .GUI ) dlgMessage( message, type = c("ok", "okcancel", "yesno", "yesnocancel"), ..., gui = .GUI ) msg_box(message) msgBox(message) ok_cancel_box(message) okCancelBox(message) ## S3 method for class 'gui' dlg_message( message, type = c("ok", "okcancel", "yesno", "yesnocancel"), ..., gui = .GUI ) ## S3 method for class 'textCLI' dlg_message( message, type = c("ok", "okcancel", "yesno", "yesnocancel"), ..., gui = .GUI ) ## S3 method for class 'nativeGUI' dlg_message( message, type = c("ok", "okcancel", "yesno", "yesnocancel"), rstudio = getOption("svDialogs.rstudio", TRUE), ..., gui = .GUI )
message |
The message to display in the dialog box. Use |
type |
The type of dialog box: |
... |
Pass further arguments to methods. |
gui |
The 'gui' object concerned by this dialog box. |
rstudio |
Logical. Should 'RStudio' dialog boxes automatically be used
if available? If |
The modified 'gui' object is returned invisibly. A string with the
name of the button ("ok"
, "cancel"
, "yes"
or "no"
) that the user
pressed can be obtained from gui$res
(see example).
msg_box()
just returns the name of the button ("ok"
), while
ok_cancel_box()
returns TRUE
if "ok" was clicked or FALSE
if "cancel"
was clicked.
On 'RStudio' or with 'zenity' under Linux, only two buttons are
available. So, when using type = "yesnocancel"
, two successive dialog boxes
are displayed: one with the message and 'yes'
/'no'
buttons, and a second
one asking to continue, and if the user clicks 'no'
, the function returns
"cancel"
. This is clearly sub-optimal. So, for a clean experience on all
supported platforms, try to avoid 'yesnocancel'
as much as possible.
## Not run: # A simple information box dlg_message("Hello world!")$res # Ask to continue dlg_message(c("This is a long task!", "Continue?"), "okcancel")$res # Ask a question dlg_message("Do you like apples?", "yesno")$res # Idem, but one can interrupt too res <- dlg_message("Do you like oranges?", "yesnocancel")$res if (res == "cancel") cat("Ah, ah! You refuse to answer!\n") # Simpler version with msgBox and okCancelBox msg_box("Information message") # Use this to interrupt script and inform user if (ok_cancel_box("Continue?")) cat("we continue\n") else cat("stop it!\n") ## End(Not run)
## Not run: # A simple information box dlg_message("Hello world!")$res # Ask to continue dlg_message(c("This is a long task!", "Continue?"), "okcancel")$res # Ask a question dlg_message("Do you like apples?", "yesno")$res # Idem, but one can interrupt too res <- dlg_message("Do you like oranges?", "yesnocancel")$res if (res == "cancel") cat("Ah, ah! You refuse to answer!\n") # Simpler version with msgBox and okCancelBox msg_box("Information message") # Use this to interrupt script and inform user if (ok_cancel_box("Continue?")) cat("we continue\n") else cat("stop it!\n") ## End(Not run)
Select an existing file, or create a new one.
dlg_open( default = "", title = if (multiple) "Select files" else "Select file", multiple = FALSE, filters = dlg_filters["All", ], ..., gui = .GUI ) dlgOpen( default = "", title = if (multiple) "Select files" else "Select file", multiple = FALSE, filters = dlg_filters["All", ], ..., gui = .GUI ) dlg_filters dlgFilters ## S3 method for class 'gui' dlg_open( default, title, multiple = FALSE, filters = dlg_filters["All", ], ..., gui = .GUI ) ## S3 method for class 'textCLI' dlg_open( default, title, multiple = FALSE, filters = dlg_filters["All", ], ..., gui = .GUI ) ## S3 method for class 'nativeGUI' dlg_open( default, title, multiple = FALSE, filters = dlg_filters["All", ], rstudio = getOption("svDialogs.rstudio", TRUE), ..., gui = .GUI )
dlg_open( default = "", title = if (multiple) "Select files" else "Select file", multiple = FALSE, filters = dlg_filters["All", ], ..., gui = .GUI ) dlgOpen( default = "", title = if (multiple) "Select files" else "Select file", multiple = FALSE, filters = dlg_filters["All", ], ..., gui = .GUI ) dlg_filters dlgFilters ## S3 method for class 'gui' dlg_open( default, title, multiple = FALSE, filters = dlg_filters["All", ], ..., gui = .GUI ) ## S3 method for class 'textCLI' dlg_open( default, title, multiple = FALSE, filters = dlg_filters["All", ], ..., gui = .GUI ) ## S3 method for class 'nativeGUI' dlg_open( default, title, multiple = FALSE, filters = dlg_filters["All", ], rstudio = getOption("svDialogs.rstudio", TRUE), ..., gui = .GUI )
default |
The default file to start with (use |
title |
A title to display on top of the dialog box. |
multiple |
Is a multiple selection of files allowed? |
filters |
A specification of file filters as a |
... |
Pass further arguments to methods. |
gui |
The 'gui' object concerned by this dialog box. |
rstudio |
Logical. Should 'RStudio' dialog boxes automatically be used
if available? If |
An object of class matrix
(inherits from array
) with 22 rows and 2 columns.
An object of class matrix
(inherits from array
) with 22 rows and 2 columns.
The modified 'gui' object is returned invisibly. The chosen file(s),
or an empty string if the "cancel" button was clicked is found in gui$res
(see example).
On 'RStudio Server', multiple = TRUE
cannot be honored for now. So,
you can only select one file there, and a warning is issued to remind you
that. On 'RStudio Desktop', the OS-native dialog box is used instead in case
of multiple = TRUE
. Also, the textual version is painful to indicate
the full path of several files. So, it should use globbing, and/or indication
of a path followed by a selection in a list (to be done in further versions).
## Not run: # Choose one R file dlg_open(title = "Select one R file", filters = dlg_filters[c("R", "All"), ])$res # Choose several files dlg_open(multiple = TRUE)$res ## End(Not run)
## Not run: # Choose one R file dlg_open(title = "Select one R file", filters = dlg_filters[c("R", "All"), ])$res # Choose several files dlg_open(multiple = TRUE)$res ## End(Not run)
Select an existing file, or create a new one to save data.
dlg_save( default = "untitled", title = "Save file as", filters = dlg_filters["All", ], ..., gui = .GUI ) dlgSave( default = "untitled", title = "Save file as", filters = dlg_filters["All", ], ..., gui = .GUI ) ## S3 method for class 'gui' dlg_save(default, title, filters = dlg_filters["All", ], ..., gui = .GUI) ## S3 method for class 'textCLI' dlg_save(default, title, filters = dlg_filters["All", ], ..., gui = .GUI) ## S3 method for class 'nativeGUI' dlg_save( default, title, filters = dlg_filters["All", ], rstudio = getOption("svDialogs.rstudio", TRUE), ..., gui = .GUI )
dlg_save( default = "untitled", title = "Save file as", filters = dlg_filters["All", ], ..., gui = .GUI ) dlgSave( default = "untitled", title = "Save file as", filters = dlg_filters["All", ], ..., gui = .GUI ) ## S3 method for class 'gui' dlg_save(default, title, filters = dlg_filters["All", ], ..., gui = .GUI) ## S3 method for class 'textCLI' dlg_save(default, title, filters = dlg_filters["All", ], ..., gui = .GUI) ## S3 method for class 'nativeGUI' dlg_save( default, title, filters = dlg_filters["All", ], rstudio = getOption("svDialogs.rstudio", TRUE), ..., gui = .GUI )
default |
The default file to start with (use |
title |
A title to display on top of the dialog box. |
filters |
A specification of file filters as a |
... |
Pass further arguments to methods. |
gui |
The modified 'gui' object is returned invisibly. The chosen file,
or an empty string (if the "cancel" button was clicked or confirmation was
cancelled) is placed in |
rstudio |
Logical. Should 'RStudio' dialog boxes automatically be used
if available? If |
In case the file already exists, the user is prompted to confirm he
wants to overwrite the existing file. If he clicks 'Cancel'
, then the
return is an empty string. The 'RStudio' version of this dialog box currently
ignores the filters =
argument.
## Not run: # Choose one R filename to save some R script into it dlg_save(title = "Save R script to", filters = dlg_filters[c("R", "All"), ])$res ## End(Not run)
## Not run: # Choose one R filename to save some R script into it dlg_save(title = "Save R script to", filters = dlg_filters[c("R", "All"), ])$res ## End(Not run)