【发布时间】:2015-08-13 21:35:50
【问题描述】:
我有一个文件,我无法在 Shiny 中读取。我的用户界面工作正常,但我认为我的问题是它在运行应用程序时没有读取数据。我将我的工作目录设置为桌面。要打开放入代码中的 csv 文件,请通过以下方式打开它:
publishers <- read.csv("App-1/data/syndicationshiny.csv")
然后在运行代码后,我正在努力运行应用程序:
runApp("App-1")
"Warning in file(file, "rt") :
cannot open file 'data/syndicationshiny.csv': No such file or directory
Error in file(file, "rt") : cannot open the connection"
所以我可以在 R 中打开它,我已经测试过了,但是当我尝试在应用程序中运行它时,它似乎找不到它。任何帮助将不胜感激
代码:
# server.R
library(shiny)
library(ggplot2)
publishers <- read.csv("App-1/data/syndicationshiny.csv")
source("helpers.R")
head(publishers)
publishers$Date_Delivered<-as.Date(publishers$Date_Delivered,'%m/%d/%Y')
shinyServer(
function(input, output) {
output$map <- renderPlot({
data <- switch(input$var,
"A" = publishers[ which(publishers$Publisher=='A'),],
"B" = publishers[ which(publishers$Publisher=='B'),],
"C" = publishers[ which(publishers$Publisher=='C'),],
"D" = publishers[ which(publishers$Publisher=='D'),],
"E" = publishers[which(publishers$Publisher=='E'),],
"F" = publishers[ which(publishers$Publisher=='F')])
color <- switch(input$var,
"A" = "darkgreen",
"B" = "black",
"C" = "darkorange",
"D" = "darkviolet",
"E" = "darkred",
"F" ="darkblue")
legend <- switch(input$var,
"A" = "A",
"B" = "B",
"C" = "C",
"D" = "D",
"E" = "E",
"F" ="F")
g<-ggplot(data,aes(data[,Date_Delivered],data[,impressions],
color = color,
legend.title = legend))+geom_line()
print(g)
})})
##ui
library(shiny)
shinyUI(fluidPage(
titlePanel("Syndication"),
sidebarLayout(
sidebarPanel(
helpText("Create Graphs on Syndication Publishers"),
selectInput("var",
label = "Choose a variable to display",
choices = c("A", "B",
"C", "D","E","F"),
selected = "A")),
mainPanel(plotOutput("map"))
)
)
)
【问题讨论】:
-
您的应用程序的文件夹/文件结构是什么?
-
你能发布你闪亮的代码吗?
-
@PauloMiraMor 刚刚发布了代码。
-
你确定路径正确吗?
-
找到文件的路径? @PauloMiraMor