Description Usage Arguments Value Examples
Output and render functions for using findInGit
within Shiny
applications and interactive Rmd documents.
1 2 3 |
outputId |
output variable to read from |
width, height |
a valid CSS unit (like |
expr |
an expression that generates a ' |
env |
the environment in which to evaluate |
quoted |
logical, whether |
FIGOutput
returns an output element that can be included in a
Shiny UI definition, and renderFIG
returns a
shiny.render.function
object that can be included in a Shiny
server definition.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | findGit <- Sys.which("git") != ""
if(findGit){
library(findInGit)
library(shiny)
# First, we create a temporary git repo
library(R.utils) # to use the `copyDirectory` function
folder1 <- system.file("htmlwidgets", package = "findInGit")
folder2 <- system.file("htmlwidgets", "lib", package = "findInGit")
tmpDir <- paste0(tempdir(), "_gitrepo")
dir.create(tmpDir)
# set tmpDir as the working directory
cd <- setwd(tmpDir)
# copy folder1 in tmpDir
copyDirectory(folder1, recursive = FALSE)
# initialize git repo
system("git init")
# add all files to git
system("git add -A")
# commit files
system('git commit -m "mycommit1"')
# create a new branch
system("git checkout -b newbranch")
# copy folder2 in tmpDir, under the new branch
copyDirectory(folder2, recursive = FALSE)
# add all files to git
system("git add -A")
# commit files
system('git commit -m "mycommit2"')
# Now let's play with Shiny
onKeyDown <- HTML(
'function onKeyDown(event) {',
' var key = event.which || event.keyCode;',
' if(key === 13) {',
' Shiny.setInputValue(',
' "pattern", event.target.value, {priority: "event"}',
' );',
' }',
'}'
)
ui <- fluidPage(
tags$head(tags$script(onKeyDown)),
br(),
sidebarLayout(
sidebarPanel(
selectInput(
"ext", "Extension",
choices = c("js", "css")
),
tags$div(
class = "form-group shiny-input-container",
tags$label(
class = "control-label",
"Pattern"
),
tags$input(
type = "text",
class = "form-control",
onkeydown = "onKeyDown(event);",
placeholder = "Press Enter when ready"
)
),
checkboxInput(
"wholeWord", "Whole word"
),
checkboxInput(
"ignoreCase", "Ignore case"
)
),
mainPanel(
FIGOutput("results")
)
)
)
Clean <- function(){
setwd(cd)
unlink(tmpDir, recursive = TRUE, force = TRUE)
}
server <- function(input, output){
onSessionEnded(Clean)
output[["results"]] <- renderFIG({
req(input[["pattern"]])
findInGit(
ext = isolate(input[["ext"]]),
pattern = input[["pattern"]],
wholeWord = isolate(input[["wholeWord"]]),
ignoreCase = isolate(input[["ignoreCase"]])
)
})
}
if(interactive()){
shinyApp(ui, server)
}else{
Clean()
}
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.