-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first version of shiny gadget interface
- Loading branch information
1 parent
7449b9e
commit e909ec2
Showing
6 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
|
||
export(jsonedit) | ||
export(jsoneditOutput) | ||
export(jsonedit_gadget) | ||
export(renderJsonedit) | ||
import(htmlwidgets) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#' Shiny Gadget for 'jsonedit' | ||
#' | ||
#' Provides a \href{http://shiny.rstudio.com/articles/gadgets.html}{Shiny gadget} | ||
#' interface for \code{jsonedit} to interactively edit and return the | ||
#' changes for use in R. | ||
#' | ||
#' @param height,width any valid \code{CSS} size unit for the | ||
#' height and width of the gadget | ||
#' @param ... arguments for \code{\link{jsonedit}} | ||
#' | ||
#' @example ./inst/examples/examples_gadget.R | ||
#' @export | ||
jsonedit_gadget <- function(..., height = NULL, width = NULL) { | ||
# modeled after chemdoodle gadget | ||
# https://github.com/zachcp/chemdoodle/blob/master/R/chemdoodle_sketcher_gadgets.R | ||
stopifnot(requireNamespace("miniUI"), requireNamespace("shiny")) | ||
ui <- miniUI::miniPage( | ||
miniUI::miniContentPanel(jsonedit(...), height=NULL, width=NULL), | ||
|
||
miniUI::gadgetTitleBar("Edit Data", right = miniUI::miniTitleBarButton("done", "Done", primary = TRUE)), | ||
|
||
htmltools::tags$script(' | ||
document.getElementById("done").onclick = function() { | ||
var listdata = JSON.parse( | ||
HTMLWidgets.find(".jsonedit").editor.getText() | ||
); | ||
Shiny.onInputChange("jsoneditordata", listdata); | ||
}; | ||
' | ||
) | ||
) | ||
|
||
server <- function(input, output, session) { | ||
shiny::observeEvent(input$done, { shiny::stopApp(input$jsoneditordata) }) | ||
shiny::observeEvent(input$cancel, { shiny::stopApp (NULL) }) | ||
} | ||
|
||
shiny::runGadget( | ||
ui, | ||
server, | ||
viewer = shiny::dialogViewer("View and Edit Data"), | ||
stopOnCancel = FALSE | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gs_wsfeed.rds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
library(listviewer) | ||
|
||
jsonedit_gadget( | ||
structure( | ||
as.list(1:4), | ||
names=letters[1:4] | ||
) | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.