【问题标题】:Shiny Error: need finite 'xlim' values in barplot闪亮的错误:在条形图中需要有限的“xlim”值
【发布时间】:2017-05-06 01:56:31
【问题描述】:

我正在开发我的第一个 Shiny 应用程序,试图制作一个反应式条形图和表格,用户可以在其中选择要显示的数据框的列,但是,当我运行应用程序时,

错误:需要出现有限的“xlim”值

.

我的数据不包含 NA,它是一个数据框,我可以使用普通的 r 命令构建非反应图。

我的代码是这样的

library(shiny)
ui <- fluidPage( 
  plotOutput(outputId = "bar_1"),
  tableOutput(outputId = "table_1"),
  selectInput("variable", "Select variable", c("colA"="colA", "colB"="colB", "colC"="Col C")) 
)  

server <- function(input, output) {
  output$bar_1<-renderPlot(barplot(table(Book1$'input$variable'))) 
  output$table1<-renderTable(table(Book1$'input$variable'))
}

shinyApp(ui = ui, server = server)

控制台显示

Warning in min(w.l) : no non-missing arguments to min; returning Inf
Warning in max(w.r) : no non-missing arguments to max; returning -Inf
Warning in min(x) : no non-missing arguments to min; returning Inf
Warning in max(x) : no non-missing arguments to max; returning -Inf
Warning: Error in plot.window: need finite 'xlim' values
Stack trace (innermost first):
    79: plot.window
    78: barplot.default
    77: barplot
    76: renderPlot
    68: output$bar_1
     1: runApp

感谢您的帮助!

【问题讨论】:

    标签: r shiny bar-chart


    【解决方案1】:

    对于一个最小的可重现示例,输出 dput(head(Book1)) 也会有所帮助。 这样更容易提供帮助

    但在您的情况下,它似乎是列的索引。试试下面的

    server <- function(input, output) {
      output$bar_1<-renderPlot(barplot(table(Book1[input$variable]))) 
      output$table1<-renderTable(table(Book1[input$variable]))
    }
    

    或者更高效一点

    server <- function(input, output) {
      current.data <- table(Book1[input$variable])
      output$bar_1<-renderPlot(barplot(current.data)) 
      output$table1<-renderTable(current.data)
    }
    

    【讨论】:

    • 您可能需要将 input$variable 放在双方括号内(即 Book1[[input$variable]])才能正常工作。如果应用程序变得更大,您还应该考虑将 Book1[[input$variable]] 移动到它自己的反应式表达式。因此,每次输入更新只需执行一次操作。它目前正在执行两次。
    • 你能解释一下你是怎么做到的吗?谢谢
    • 成功了!当函数响应时,为什么必须使用没有 $ 的方括号?我在教程上睡了吗?
    • 我已经包含了@Gladwell 的建议,但是,预先计算了整个表格。
    • @CamiloMonge:使用美元符号,您试图检索名为“input$variable”的列,而 Book1[input$variable] 将检索名为 value 的列。 "input$variable" 的方括号版本是 Book1["input$variable"] (注意引号)
    猜你喜欢
    • 2016-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-16
    • 1970-01-01
    • 1970-01-01
    • 2018-01-26
    • 1970-01-01
    相关资源
    最近更新 更多