我尝试上传我在网上创建的R Shiny应用程序,但它一直在说 '找不到对象营养'。我的文件一起位于一个文件夹中,我只是按下R控制台上的发布按钮。
我的ui.R代码:
library(shiny)
shinyUI(fluidPage(
titlePanel("Nutrition Data App"),
p(em("This Dataset contains nutrition data on fastfood places")),
p(strong("This app allows users to browsefood items and places and see nutritional value!")),
sidebarLayout(
sidebarPanel(
selectInput("Location","Location",
choice = c(levels(Nutrition$Location)),
selected = "KFC")
),
mainPanel(
plotOutput("barplot"),
br(),br(),
verbatimTextOutput("text")
)
)
))
我的服务器.R代码:
Nutrition <- read.csv("NutritionData.csv", header=T, na.strings=c("","NA"))
Nutrition = Nutrition[,1:10]
Nutrition$Location = as.factor(Nutrition$Location)
library(dplyr)
library(shiny)
library(ggplot2)
shinyServer(function(input, output) {
filtered = reactive({
Nutrition %>%
filter(Location == input$Location
)
})
output$barplot = renderPlot({
Calories = filtered()[,4]
hist(Calories,xlim = c(0,1000),ylim = c(0,30),col = c("blue"))
})
output$text = renderPrint({
cat("The mean calories of the selected group is", mean(filtered()$Calories))
})
})
发生了什么事?
答案 0 :(得分:0)
Dunno ..这段代码对我来说很好:
ui = fluidPage(
titlePanel("Nutrition Data App"),
p(em("This Dataset contains nutrition data on fastfood places")),
p(strong("This app allows users to browsefood items and places and see nutritional value!")),
sidebarLayout(
sidebarPanel(
selectInput("Location","Location",
choice = c(levels(Nutrition$Location)),
selected = "KFC")
),
mainPanel(
plotOutput("barplot"),
br(),br(),
verbatimTextOutput("text")
)
)
)
Nutrition <- read.csv("e://NutritionData.csv", header=T, na.strings=c("","NA"))
Nutrition = Nutrition[,1:10]
Nutrition$Location = as.factor(Nutrition$Location)
library(dplyr)
library(shiny)
library(ggplot2)
server =shinyServer(function(input, output) {
filtered = reactive({
Nutrition %>%
filter(Location == input$Location
)
})
output$barplot = renderPlot({
Calories = filtered()[,4]
hist(Calories,xlim = c(0,1000),ylim = c(0,30),col = c("blue"))
})
output$text = renderPrint({
cat("The mean calories of the selected group is", mean(filtered()$Calories))
})
})
shinyApp(ui = ui, server = server)