我是R的新手,并尝试复制教程中的条形图Shiny示例(Link。但是,我收到一个错误。这是因为数据帧的类型吗?我读了其他几个&#39 ; 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
server.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")
)
)
)
)
答案 0 :(得分:1)
您收到此错误是因为table
函数的输出不是数据框而是table
。
尝试:
df <- as.data.frame(unclass(table(call$Facility, call$name)))
此外,在server.R
中,当您获得input
数据时,您会收到拼写错误,inputId
中的Name
为ui.R