这是一个可重现的示例,靠近我正在开发的 Shiny App:
library(ggplot2)
library(shiny)
ui <- basicPage(
plotOutput("plot1", hover = "plot_hover"),
verbatimTextOutput("info")
)
server <- function(input, output) {
output$plot1 <- renderPlot({
ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point()
})
output$info <- renderPrint({
nearPoints(mtcars, input$plot_hover, threshold = 10, maxpoints = 1,
addDist = TRUE)[1]
})
}
shinyApp(ui, server)
我只想显示 mpg 值,没有行名。我用nearPoints试过这个:
nearPoints(mtcars, input$plot_hover, threshold = 10, maxpoints = 1,addDist = TRUE)[1,1], which resulted in:
我想要的只是 mpg 值,没有行名,没有 [ 1 ],什么都没有。如何才能做到这一点?
cat() 可用于执行此操作。
下面的代码,应该为你做的伎俩
output$info <- renderPrint({
val <-nearPoints(mtcars, input$plot_hover, threshold = 10, maxpoints = 1,addDist = TRUE)[1,1]
cat(val)
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句