대화 형 플로팅 반짝이 응용 프로그램에 재설정 버튼을 추가하고 싶습니다. 응용 프로그램은 다음과 같은 작업을 수행합니다 : 마우스가 클릭되면 마우스의 위치를 캡처하고 그 위치에 빨간색 점을 그리고 파란색 선으로 이전 위치를 모두 연결합니다. 재설정 버튼을 누르면 모든 빨간색 점과 파란색 선을 제거하고 새로운 플로팅 프로세스를 시작해야합니다. 그러나 실제로 리셋 버튼을 클릭하면 마지막 빨간색 점이 여전히 플로팅 영역에 남아 있습니다. 나는 무엇이 잘못되었는지 확신하지 못한다. 도와 줘서 고마워.Rshiny 대화 형 플로팅에 재설정 버튼 넣기
추신 : 줄거리 마우스 이벤트를 제공 한 데 감사드립니다.
library(shiny)
N = 30 # sample size
x = sort(runif(N, 0, 10)); y = x + rnorm(N)
xval=NULL
yval=NULL
shinyServer(function(input, output) {
get.coords <- reactive({
data.frame(x=input$coords$x, y=input$coords$y)
})
actiontype <- reactiveValues()
actiontype$lastAction <- 'draw'
observe({
if (input$reset != 0)
actiontype$lastAction <- 'reset'
})
observe({
if (input$closepolygon != 0)
actiontype$lastAction <- 'closepolygon'
})
output$diagPlot = renderPlot({
plot(x, y, xlim = range(x), ylim = range(y))
grid()
if (identical(actiontype$lastAction, 'reset')) {
xval <<- NULL
yval <<- NULL
actiontype$lastAction <- 'draw'
} else if (identical(actiontype$lastAction, 'draw')){
temp <- get.coords()
xval <<- c(xval,temp$x)
yval <<- c(yval,temp$y)
points(xval, yval, pch = 19, col = 'red', cex = 1.5)
for (i in 1:(length(xval)-1))
lines(c(xval[i],xval[i+1]),c(yval[i],yval[i+1]),type="l",col="blue")
if(identical(actiontype$lastAction, 'closepolygon'))
lines(c(xval[1],xval[length(xval)]),c(yval[1],yval[length(yval)]),type="l",col="blue")
}
}, width = 700, height = 600)
})
을 그리고 ui.R
library(shiny)
shinyUI(pageWithSidebar(
headerPanel('iPED: The interactive ChIP-PED analysis platform'),
sidebarPanel(
helpText("graph"),
actionButton('closepolygon', 'Close the Polygon'),
actionButton('reset', 'Reset')
),
mainPanel(
plotOutput('diagPlot', clickId="coords", height="auto", width="100%")
)
))
이것은 정말 도움이됩니다. 고마워. 나는 앱을 더 개발하는 중이 야. – jasoncolts