readkeygraph <- function(prompt)
{
getGraphicsEvent(prompt = prompt,
onMouseDown = NULL, onMouseMove = NULL,
onMouseUp = NULL, onKeybd = onKeybd,
consolePrompt = "[click on graph then follow top prompt to continue]")
Sys.sleep(0.01)
return(keyPressed)
}
onKeybd <- function(key)
{
keyPressed <<- key
}
xaxis=c(1:10) # Set up the x-axis.
yaxis=runif(10,min=0,max=1) # Set up the y-axis.
plot(xaxis,yaxis)
for (i in xaxis)
{
# On each keypress, color the points on the graph in red, one by one.
points(i,yaxis[i],col="red", pch=19)
keyPressed = readkeygraph("[press any key to continue]")
}
在这里,您可以看到图表,其中一半的点彩色,等待下一个键盘上的击键。
兼容性: 在环境下使用 win.graph 或 X11进行测试。适用于 Windows 7 x64和 Revolution R v6.1。不能在 RStudio 下工作(因为它不使用 win.graph)。
library(shiny)
ui <- fluidPage(actionButton("button", "Press the button"))
server <- function(input, output) {observeEvent(input$button, {stopApp()})}
runApp(shinyApp(ui = ui, server = server))
print("He waited for you to press the button in order to print this")