基于的信息 http://shiny.rstudio.com/articles/selecting-rows-of-data.html 我正在使用互动情节进行初步体验。
使用正常情节(在笛卡尔坐标系上),一切都很棒。 当谈到三元图时,它更棘手。三元图有三个变量,函数nearPoints()只有两个参数来标识图上的位置:xvar和yvar。
以下代码演示了此问题:
library(ggtern)
library(shiny)
## data ####
dd <- data.frame(x=c(3,1,5), y=c(45,29,10), z=c(10,45,94),
ss = c(58,75,109))
################
runApp(## UI ####
list(
ui = (basicPage(
headerPanel("interactive tests"),
mainPanel(
plotOutput("f1", click = "plot_click1"),
verbatimTextOutput("info1"),
plotOutput("f2", click = "plot_click2"),
verbatimTextOutput("info2")
)
)),
## server ####
server = function(input, output) {
output$f1 <- renderPlot({
plot(dd$x,dd$y)
})
output$f2 <- renderPlot({
figura <- ggtern(data = dd,
aes(x = x,y = y,z = z)) +
geom_point()
print(figura)
})
output$info1 <- renderPrint({
nearPoints(dd, input$plot_click1, xvar = "x", yvar = "y")
})
output$info2 <- renderPrint({
nearPoints(dd, input$plot_click2, xvar = "x", yvar = "y")
})
}
)
)
第一个图是一个简单的散点图,其中单击一个观察返回数据框中的相应行。
第二个图是三元图,在这种情况下它不起作用。
如果某人有解决方案或能指出我正确的方向,那就太好了。
谢谢, 安东尼奥