我想在我的应用程序中创建一个页面,其中有一个图像,并且可以在图像的特定坐标中添加数字输出或文本输出。您可以在下图中找到一个示例(右侧的轴)
您能告诉我是否可以创建类似的东西吗?
答案 0 :(得分:0)
您可以使用plot
函数来使用text
函数来绘制光栅文件和注释。请参见下面的代码:
library(png)
library(shiny)
library(RCurl)
# Define UI for application that draws a histogram
ui <-fluidPage(
titlePanel("Annotated plot output"),
fluidRow(
plotOutput("plot1")
)
)
# Define server logic required to draw a histogram
server <- function(input, output, session) {
output$plot1 <- renderPlot({
myurl <- "https://i.stack.imgur.com/GcpUb.png"
ima <- readPNG(getURLContent(myurl))
op <- par(mar = rep(0, 4))
plot(NULL, xlim = c(0, 100), ylim = c(0, 100), xaxs = "i", yaxs = "i")
rasterImage(ima, 0, 0, 100, 100, interpolate = TRUE)
text(50, 50, "Custom Label1", col = "red", cex = 2)
text(25, 25, "Custom Label2", col = "red", cex = 2)
par(op)
})
}
# Run the application
shinyApp(ui = ui, server = server)