我想更改文本输出以显示有关悬停的绘图点的特定信息,例如名称和值等,但是我似乎无法锻炼如何更改VerbatimTextOutput,并且当前显示的内容用处不大快速浏览信息。这是我正在使用的代码:
```
ui <- fluidPage(
fluidRow(
column(width = 8, class = "well",
h4("Brush to select region. Left plot controls right plot"),
fluidRow(
column(width = 12,
plotOutput("plot2", height = 300,
brush = brushOpts(
id = "plot2_brush",
resetOnNew = TRUE
)
)
),
column(width = 12,
plotOutput("plot3", height = 300, hover = hoverOpts(id = "plot_hover"))
)
)
),
column(width = 3,
verbatimTextOutput("hover_info", placeholder = TRUE))
)
)
server <- function(input, output) {
# Linked plots (middle and right)
ranges2 <- reactiveValues(x = NULL, y = NULL)
output$plot2 <- renderPlot({
ggplot(adj_p_val_df, aes(x = Genes, y = p_value, col = Model))+
geom_point()+
theme(legend.position = "none")
})
output$plot3 <- renderPlot({
ggplot(adj_p_val_df, aes(x = Genes, y = p_value, col = Model))+
geom_point() +
coord_cartesian(xlim = ranges2$x, ylim = ranges2$y, expand = FALSE)
})
output$hover_info = renderPrint({
cat("Gene info:\n")
str(input$plot_hover)
})
output$placeholder = renderTe
# When a double-click happens, check if there's a brush on the plot.
# If so, zoom to the brush bounds; if not, reset the zoom.
observe({
brush <- input$plot2_brush
if (!is.null(brush)) {
ranges2$x <- c(brush$xmin, brush$xmax)
ranges2$y <- c(brush$ymin, brush$ymax)
} else {
ranges2$x <- NULL
ranges2$y <- NULL
}
})
}
shinyApp(ui, server)
```