-1
我想知道是否可以使用带有滑块输入的交互式图形中的nearPoints()
获取行数据。我app.R文件看起来像:带滑块输入的闪亮nearPoints()
library('shiny')
library('ggplot2')
dt <-read.csv('file.csv')
ui <- fluidPage(
plotOutput("plot1", height = 550, click = "plot1_click"),
fluidRow(
column(3,
sliderInput("Obs", "Number of Books", min = 1, max = nrow(up), value = 50)
),
column(3, offset = 3,
h4("Legends"),
verbatimTextOutput("selected")
)
)
)
server <- function(input, output) {
mydata <- reactive({
dt[1:as.numeric(input$Obs),]
})
output$plot1 <- renderPlot({
test <- mydata()
ggplot(data = test, aes(x = test[,2], y = test[,1])) + geom_point()
})
output$selected <- renderPrint({
file <- mydata()
nearPoints(file, input$plot1_click, threshold = 10, maxpoints = 1,
addDist = FALSE)
})
}
shinyApp(ui = ui, server = server)
闪亮nearPoints()
是没有这个滑块输入可以正常使用。当我使用滑块输入时,我无法获取行数据直到max。有没有使用滑块输入的方法?任何帮助表示赞赏。
你尝试过使用renderUI吗? – amrrs
只是为了检查我的理解,您希望'input $ plot1_click'中的值在'sliderInput'中使用?如果这就是你想要的,你需要将'sliderInput'函数移动到'server.R'中的'renderUI'输出函数中。然后你可以用'uiOutput'在'ui.R'中渲染它。这里是[相关文档](https://shiny.rstudio.com/reference/shiny/latest/renderUI.html) –
滑块输入是“Obs”,它控制传递给函数的行数。 “输入$ plot1_click”是鼠标点击的点。 –