我尝试了一些解决方案,使用
ggplot
但在缩放方面存在一些问题
plotOutput
作用在帮助页面中(
http://shiny.rstudio.com/reference/shiny/latest/plotOutput.html
),请注意以下事项:
绘图输出
,如果可能,坐标将按比例发送到数据空间。(目前,基本图形和ggplot2生成的绘图支持此缩放,但晶格和其他图形生成的绘图不支持。)如果无法缩放,将发送原始像素坐标。对于
imageOutput
,坐标将以原始像素坐标发送。
使用ggplot2图形
renderPlot
应返回ggplot对象;如果相反,代码将打印ggplot2对象,如下所示
print(p)
,则交互图形的坐标将无法正确缩放到数据空间。
我试着移动
gg图
到脚本的服务器部分,但它不起作用。
library(shiny)
library(dplyr)
library(maps)
library(mapdata)
mapPoints <- data.frame(Longitude=c(-103, -108, -130, -120),
Latitude=c(52, 40, 45, 54))
ui <- fluidPage(
fluidRow(
column(width = 6,
plotOutput("plot1", height = 300,
click = "plot1_click", brush = "plot1_brush") )
),
fluidRow(
column(width = 6,
h4("Near points"), verbatimTextOutput("click_info") ),
column(width = 6,
h4("Brushed points"), verbatimTextOutput("brush_info") )
)
)
server <- function(input, output) {
# output world map
output$plot1 <- renderPlot({
map('worldHires')
points(mapPoints$Longitude, mapPoints$Latitude,
col = "red", pch = 16)
})
# output clicked points
output$click_info <- renderPrint({
nearPoints(mapPoints, xvar="Longitude",
yvar="Latitude", input$plot1_click)
})
# output brushed points
output$brush_info <- renderPrint({
brushedPoints(mapPoints, xvar="Longitude",
yvar="Latitude", input$plot1_brush)
})
}
shinyApp(ui, server)