【问题标题】:Need finite 'xlim' values for R ShinyR Shiny 需要有限的“xlim”值
【发布时间】:2015-03-08 01:18:27
【问题描述】:

我是 R 新手,并尝试复制教程中的 barplot Shiny 示例(Link。但是,我遇到了一个错误。这是因为数据框的类型吗?我阅读了其他几个“xlim”错误页面, 并且似乎没有得到任何结果,因为它们主要用于非条形图示例。我已经以与示例相同的结构复制了数据框,这是我想要开始的地方。任何帮助将不胜感激。

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
Error in plot.window(xlim, ylim, log = log, ...) : 
  need finite 'xlim' values

df:

             Name           
Facility    Atlanta Chicago Boston  New York
Home        5   0   12  5
Post Acute  23  5   43  0
Relative    7   72  33  0
Hospital    18  34  19  67

服务器.R

library(shiny)

## Define where the data file exists
setwd("C:/Users/R")

## Name the object to hold csv
dta <- read.csv(file = "data.csv", na.strings =c("", "NA"))

## Assign new object as data frame and get column info
call <- data.frame(dta)

df <- table(call$Facility, call$name)

shinyServer(function(input, output){
#   # Create the data frame to display     

    output$dcPlot <- renderPlot({

      # Render a barplot
      barplot(df[,input$name],
              main=input$name,
              ylab="Number of Discharges",
              xlab="Discharge Type")
    })
 })

这里是 ui.R

# Bring in the library
library(shiny)

# Define the overall UI
shinyUI(

  # Use a fluid Bootstrap layout
  fluidPage(    

    # Give the page a title
    titlePanel("Discharge by Provider"),

    # Generate a row with a sidebar
    sidebarLayout(      

      # Define the sidebar with one input
      sidebarPanel(
        selectInput(inputId = "Name",
                    label = "Name:",
                    choices=colnames(df)),
        hr(),
        ## This input goes below the drop down bars 
        helpText("Data from Episode Connect monthly Call Forms")
      ),

      # Create a spot for the barplot
      mainPanel(
        plotOutput("dcPlot")  
      )

    )
  )
)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    您收到此错误是因为table 函数的输出不是数据帧,而是table

    试试:

    df <- as.data.frame(unclass(table(call$Facility, call$name)))
    

    另外,在您的server.R 中,当您获得input 数据时,您有一个错字,inputId 在您的ui.R 中是Name

    【讨论】:

    • 啊,伙计,我什至无法告诉你这让我多么开心。谢谢你。我要弄清楚的下一件事是沿 x 轴的条形图标签。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-27
    • 2016-11-28
    • 2018-01-26
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    相关资源
    最近更新 更多