1
ポイントの色がマウスポインタ(ホバー)に依存する、Rmarkdownドキュメントに光沢のあるプロットを作成したいと思います。しかし、入力リストのホバー要素が再びNULL
に設定されるまで、必要なプロットは数秒で表示されます。どうしてこれなの?Rのホバーに基づくポイントカラーshinyとRmarkdown
例:あなたは、プロットの色の部分を削除した場合
---
title: "Untitled"
runtime: shiny
output: html_document
---
```{r,echo=FALSE}
library(ggplot2)
x <- rnorm(100)
y <- rnorm(100)
dfr <- data.frame(x, y)
give_col <- function(){
if(is.null(input$hover$y)){
rep(2, length(x))
}else{
(input$hover$y < dfr$y) + 1
}}
imageOutput("image_id", hover = "hover")
textOutput("text_id")
output$image_id <- renderPlot({
plot(dfr$x, dfr$y, col = factor(give_col()))
# plot(dfr$x, dfr$y) # Without col the give_col() element remains
# as can be seen in the output text
})
output$text_id <- reactive({paste(give_col())})
```
、テキスト出力が期待通りに動作するので、私はそれがpch
代わりのcol
かとのために(同じ自体プロットで何かでなければならないと思いますplot()
の代わりにggplot()
)。
ご協力いただければ幸いです。
おかげで、素早く簡単かつへのポイントの答えのために! – user1965813
なぜ 'input $ hover'を変更する再プロットが' observeEvent'を引き起こさないのでしょうか? (これは、 'observeEvent'が単純な無効化とは異なる動作をすることを意味します) 答えが見つかりました[ここ](https://shiny.rstudio.com/reference/shiny/latest/observeEvent.html) – user1965813