我正在尝试将我的闪亮应用程序部署在Shinyapps.io上,并且我收到此消息:
”发生了错误 该应用程序无法启动(以代码1退出)。“
我试图提交setwd line和其他内容,但是我没有找到解决方法。
问题可能是文件路径错误?我应该将“ read.csv”行放入服务器或ui函数中吗?
这是我的代码:
#setwd(dir = "/media/miles/MILES/Projets & Cours/Master_1/Semestre 2/lardjane/Shiny_app/Projet Shiny")
matches <- read.csv('./matches.csv', stringsAsFactors=FALSE, sep=",", header=TRUE)
matches <- matches[,c(3,6)]
#summary(matches)
matches$platformid <- as.factor(matches$platformid)
#levels(matches$platformid)
#install.packages('shiny')
library(shiny)
#install.packages('rsconnect')
library(rsconnect)
ui <- shinyUI(fluidPage(
# Give the page a title
titlePanel("Game time by server"),
# Generate a row with a sidebar
sidebarLayout(
# Define the sidebar with one input
sidebarPanel(
selectInput("region", "Server:",
choices=levels(matches$platformid)),
hr(),
selectInput(inputId = "n_breaks",
label = "Number of bins in histogram (approximate):",
choices = c(10, 20, 35, 50),
selected = 20),
hr(),
checkboxInput(inputId = "individual_obs",
label = strong("Show individual observations"),
value = FALSE),
checkboxInput(inputId = "density",
label = strong("Show density estimate"),
value = FALSE),
conditionalPanel(condition = "input.density == true",
sliderInput(inputId = "bw_adjust",
label = "Bandwidth adjustment:",
min = 0.2, max = 2, value = 1, step = 0.2)),
hr(),
helpText("Data from Kaggle (2014-2018) League of Legends Ranked Matches.")
),
# Create a spot for the barplot
mainPanel(
plotOutput("timePlot")
)
)
)
)
server <- function(input, output) {
# Fill in the spot we created for a plot
output$timePlot <- renderPlot({
# Render a histogramme
hist(matches[matches$platformid==input$region,2],
probability = TRUE,
breaks = as.numeric(input$n_breaks),
main = "Game Time",
ylab="",
xlab="Duration (seconds)")
if (input$individual_obs) {
rug(matches[matches$platformid==input$region,2])
}
if (input$density) {
dens <- density(matches[matches$platformid==input$region,2],
adjust = input$bw_adjust)
lines(dens, col = "blue")
}
})
}
shinyApp(ui = ui, server = server)
我想添加最后一个请求。我想在绘图下方显示R代码。这样任何人都可以访问两者(应用程序结果和R代码)。有可能吗?
谢谢。
答案 0 :(得分:2)
swd不是解决此问题的方法,因为Shiny(通常是R)中的环境是如何工作的。当您启动Shiny时,您实际上并不知道Shiny服务器在哪台物理服务器上运行。因此,您需要使用通用解决方案。
尝试一下:
matches <- read.csv('./matches.csv',
stringsAsFactors=FALSE, sep=",", header=TRUE)
答案 1 :(得分:0)
对于每个https://docs.rstudio.com/shinyapps.io/Storage.html,如果csv文件与应用程序位于同一位置,请尝试:
matches <- read.csv('matches.csv', stringsAsFactors=FALSE, sep=",", header=TRUE)
但是,我认为这不是您的问题;我认为问题出在您绘制剧情上。您使用input$region
生成直方图,但没有提供默认值,因此它以NULL
开头,这在尝试构建直方图时会引起问题。您有2个解决方案。
选项1用于为input$region
设置默认值:
selectInput("region", "Server:",
choices=levels(matches$platformid),
selected = levels(matches$platformid)[1]),
选项2使用req()
,以使直方图在其任何必需值都不为truthy时都不会运行:
server <- function(input, output) {
# Fill in the spot we created for a plot
output$timePlot <- renderPlot({
req(input$region, input$n_breaks)
# Render a histogramme
hist(matches[matches$platformid==input$region,2],
probability = TRUE,
breaks = as.numeric(input$n_breaks),
main = "Game Time",
ylab="",
xlab="Duration (seconds)")
if (input$individual_obs) {
rug(matches[matches$platformid==input$region,2])
}
if (input$density) {
dens <- density(matches[matches$platformid==input$region,2],
adjust = input$bw_adjust)
lines(dens, col = "blue")
}
})
}