【问题标题】:R Shiny dataTableOutput not displaying Brushed PointsR Shiny dataTableOutput 不显示拉丝点
【发布时间】:2015-07-16 04:28:35
【问题描述】:

我正在使用 ggplot2 数据集中的 Iris 数据开发 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)

我应该注意到数据表显示并且您可以看到它刷新,它只是没有填充任何数据。

编辑

上面的脚本有一个功能,当且仅当您选择绘图的整个区域时,它才会显示数据表中的所有值。

【问题讨论】:

    标签: r ggplot2 shiny brush


    【解决方案1】:

    我遇到了类似的问题。我最终修复了它(在阅读了这篇文章后:https://github.com/rstudio/shiny/issues/998),方法是不在情节上调用 print,只是返回它。所以:

    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
    })
    

    【讨论】:

      【解决方案2】:

      我遇到了完全相同的问题,但即使选择了所有点,我也无法渲染输出:

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

      我在这里找到了解决方案: R Shiny does not display the output data table

      这似乎对我有用:

        brushd <- reactive({
          user_brush <- input$mapbrush
          brushedPoints(acled_selected(), user_brush, xvar = "LONGITUDE", yvar = 
      "LATITUDE")
          })
      
        output$dt<-DT::renderDataTable({DT::datatable(brushd())})
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-24
        • 1970-01-01
        • 2015-11-13
        • 2017-09-18
        • 1970-01-01
        • 2021-08-12
        • 2019-03-06
        • 2019-06-08
        相关资源
        最近更新 更多