簡體   English   中英

R閃亮的dataTableOutput不顯示刷點

[英]R Shiny dataTableOutput not displaying Brushed Points

我正在使用ggplot2數據集中的虹膜數據開發R Shiny儀表板。 它具有三個主要組件:一個側欄面板,用於選擇要在繪圖中顯示的變量;一個帶有刷點的ggplot;以及一個在其下方顯示刷點數據的數據表。 一切工作正常,只是數據表似乎沒有選擇表上的數據點。 據我所知,這與服務器中的output $ plot_brushed_points行有關。 任何幫助將不勝感激!

library(shiny)
library(ggplot2)

useri <- shinyUI(pageWithSidebar(
headerPanel("Reactive Plot"),
sidebarPanel(
selectInput('x','X-Axis',names(iris)),
selectInput('y','Y-Axis',names(iris)),
selectInput('color','Color',c('None',names(iris[5])))),
mainPanel(uiOutput("plotui"),dataTableOutput("plot_brushed_points"))))

serveri <- shinyServer(function(input,output) {
output$plot <- renderPlot({
p <- ggplot(iris,aes_string(x=input$x, y=input$y))+geom_point()+theme_bw()
if(input$color != 'None')
  p <- p + aes_string(color=input$color)
print(p)
})
output$plotui <- renderUI(plotOutput("plot",brush = brushOpts("plot_brush")))
output$plot_brushed_points <- renderDataTable(brushedPoints(iris,input$plot_brush,input$x,input$y), options=list(searching=FALSE, paging = FALSE))
})

shinyApp(useri, serveri)

我應該注意,數據表顯示出來,您可以看到它刷新了,只是其中沒有任何數據。

編輯

上面的腳本具有一項功能,當且僅當您選擇整個繪圖區域時,它才會顯示數據表中的所有值。

我遇到了完全相同的問題,除了即使選擇了所有點也無法渲染輸出:

output$dt <- renderDT(
  expr = brushedPoints(acled_selected(), input$mapbrush), 
  options = list(lengthChange = FALSE, rownames=FALSE)
  )

我在這里找到了解決方案: R Shiny不顯示輸出數據表

這似乎為我工作:

  brushd <- reactive({
    user_brush <- input$mapbrush
    brushedPoints(acled_selected(), user_brush, xvar = "LONGITUDE", yvar = 
"LATITUDE")
    })

  output$dt<-DT::renderDataTable({DT::datatable(brushd())})

我有一個類似的問題。 我最終通過不調用圖上的print,而只是將其返回來修復了它(在閱讀了這篇文章之后: https : //github.com/rstudio/shiny/issues/998 )。 所以:

output$plot <- renderPlot({
p <- ggplot(iris,aes_string(x=input$x, y=input$y))+geom_point()+theme_bw()
if(input$color != 'None')
p <- p + aes_string(color=input$color)
#print (p)
p
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM