8
私はshiny
アプリを持っていて、開始時にbrush
のggplot
を入力したいので、ユーザーはアプリが起動するたびに興味のある領域を選択する必要はありません。後でもちろん、ユーザーは別のエリアを選択することができます。ここから始める例を次に示します。光沢のあるアプリでggplotのブラシを初期化することはできますか?
library(shiny)
library(ggplot2)
runApp(shinyApp(
ui = fluidPage(plotOutput('plotA', brush = brushOpts(id = 'plotA_brush')),
plotOutput('plotZ')),
server = function(input, output, session) {
pollData <- reactivePoll(60 * 1000, session,
checkFunc = function(){ Sys.time() },
valueFunc = function(){ data.frame(x = 1:100, y = cumsum(rnorm(100)))})
output$plotA <- renderPlot({
dt <- pollData()
ggplot(dt, aes(x, y)) + geom_line()
})
ranges <- reactiveValues(x = NULL, y = NULL)
observe({
brush <- input$plotA_brush
if(!is.null(brush)) {
ranges$x <- c(brush$xmin, brush$xmax)
ranges$y <- c(brush$ymin, brush$ymax)
} else {
ranges$x <- NULL
ranges$y <- NULL
}
})
output$plotZ <- renderPlot({
dt <- pollData()
ggplot(dt, aes(x, y)) + geom_line() + coord_cartesian(xlim = ranges$x, ylim = ranges$y)
})
}
))
は、しかし何にそれを初期化?それは全体の領域に "初期化"を開始します。私はあなたが特定の部分にそれを初期化したいと思うが、どの部分?全体よりも小さいものは何ですか? –
はい、すべてのものよりも小さいものはありません。この特定の例では、 'x'が25から75の範囲にあり、' y'が最小から最大になるようにしたいとしましょう。 –