我有一個可重現的閃亮,我試圖為情節實作brushedPoints,但是,我只是得到了錯誤。有什么辦法可以解決這個問題,以便當我在繪圖上單擊或使用畫筆選擇一個點時,與之相連的資料會出現在表格中?提前致謝
錯誤:brushedPoints: 'xvar' ('x') not in names of input
library(shiny)
library(plotly)
dataset <- mtcars
ui <- shinyUI(pageWithSidebar(
headerPanel("Mtcars"),
sidebarPanel(sliderInput('sampleSize', 'Sample Size', min=10, max=nrow(dataset),
value=min(10, nrow(dataset)), step=5, round=0),
selectInput('x', 'X', names(dataset)),
selectInput('y', 'Y', names(dataset), names(dataset)[[2]]),
selectInput('color', 'Color', c('None', names(dataset))),
checkboxInput('smooth', 'Smooth'),
selectInput('facet_row', 'Facet Row', c(None='.', names(dataset))),
selectInput('facet_col', 'Facet Column', c(None='.', names(dataset))),
hr(),
checkboxInput("plotly1", "Interactive plot!",value = FALSE, width=140),
actionButton("plot", "Plot!")
),
mainPanel(
plotOutput('plot', click = "plot_click",
hover = hoverOpts(id = "plot_hover", delayType = "throttle"),
brush = brushOpts(id = "plot_brush")),
tableOutput("plot_brushedpoints")
)
))
server<- shinyServer(function(input, output) {
dataset <- reactive( { mtcars[sample(nrow(mtcars), input$sampleSize),] })
gragh <- reactive({
p <- ggplot(dataset(), aes_string(x=input$x, y=input$y)) geom_point()
if (input$color != 'None')
p <- p aes_string(color=input$color)
facets <- paste(input$facet_row, '~', input$facet_col)
if (facets != '. ~ .')
p <- p facet_grid(facets)
if (input$smooth)
p <- p geom_smooth()
p
}) |> bindEvent(input$plot)
output$plot <- renderPlot({
gragh()
})
output$plot_brushedpoints <- renderTable({
df<- mtcars
res <- brushedPoints(df, input$plot_brush, "x", "y",allRows = TRUE)
if (nrow(res) == 0|is.null(res))
return(NULL)
res
})
})
uj5u.com熱心網友回復:
不確定您要對“x”和“y”做什么。洗掉它們使其作業:
res <- brushedPoints(df, input$plot_brush, allRows = TRUE)
您將“x”和“y”放入 xvar 和 yvar,但這些必須是 df 中的列名。
brushedPoints(
df,
brush,
xvar = NULL,
yvar = NULL,
panelvar1 = NULL,
panelvar2 = NULL,
allRows = FALSE
)
xvar, yvar
A string giving the name of the variable on the x or y axis.
These are only required for base graphics, and must be the name of a column in df.
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/488008.html
上一篇:您可以在水平條之間放置標簽嗎?
下一篇:一個繪圖中的多個圖形ggplot
