Shiny App - 数据 Table 在 运行 本地显示,但在发布时不显示
Shiny App - Data Table Displays when Running Locally but not When Published
我构建了一个 Shiny 应用程序,该应用程序依赖于在启动时加载本地存储的 CSV 文件。当我 运行 我电脑上的 Shiny 应用程序时,无论是在 RStudio window 还是 Google Chrome 中,应用程序都可以毫无问题地加载和显示数据。即使没有将数据加载到 R 会话中也是如此。但是,在发布应用程序后,主要数据 table 不会在启动时或点击提交按钮后显示(试图刷新 table)。
当我从使用 Shiny 的数据 table 函数切换到使用 DT 时,这个问题就开始了。我开始使用 DT 是为了能够使第一列中的名称充当链接。我目前正在开发 64 位 Macbook 运行ning Mavericks。今天刚刚在故障排除时更新了 R 和 RStudio。我也尝试从计算机 运行ning Windows 8 发布 - 数据 table 仍然没有显示在已发布的应用程序版本中。
ui.r代码:
shinyUI(fluidPage(
titlePanel("Pinball Buyer's Guide"),
sidebarLayout(
sidebarPanel(
helpText("Whether you're looking for a great value on a machine to buy or just want to find a new table you'd
like to play, this guide will help you find a table based on your tastes. Use the sliders below to
assign a weight to each category of your table ranking score. The site will use that to generate
a score for each of the available tables and to determine how much bang for your buck each table
represents."),
sliderInput('rating',
label = 'Player Ratings',
value = 1, min = 0, max = 5, step = .25),
sliderInput('game',
label = 'Game Design',
value = 1, min = 0, max = 5, step = .25),
sliderInput('art',
label = 'Art',
value = 1, min = 0, max = 5, step = .25),
sliderInput('sound',
label = 'Sound',
value = 1, min = 0, max = 5, step = .25),
sliderInput('other',
label = 'Other Game Aspects',
value = 1, min = 0, max = 5, step = .25),
sliderInput('staff',
label = 'Pinside Staff Ratings',
value = 1, min = 0, max = 5, step = .25),
helpText("Excluding the production year in the pricing model will likely push older tables
to the top of the bargain rankings. If you'd prefer a newer machine, leave this checked."
),
checkboxInput('year',
label = 'Include Machine Year in Price Model?',
value = TRUE),
submitButton('Submit')
),
mainPanel(
tabsetPanel(
tabPanel("Main",
br(),
textOutput('topTableExplainer'),
br(),
dataTableOutput('topTables'),
br()
),
tabPanel("About This App",
tags$body(textOutput('summary')),
br()
)
)
)
)
))
server.r代码:
library(DT)
pinData <- read.csv('./Data/pinDataMassaged.csv', header=TRUE, stringsAsFactors = FALSE)
userTable <- data.frame()
shinyServer(function(input, output){
getUserFrame <- reactive({
userScore <- pinData$rating * input$rating + pinData$gameDesign * input$game + pinData$artwork * input$art +
pinData$sound * input$sound + pinData$otherRating * input$other + pinData$staffRating * input$staff
userTable <- data.frame()
userTable <- data.frame(pinData, userScore)
if (input$year == 'TRUE'){
userModel <- lm(avgValue ~ userScore + age, data = userTable)
} else{
userModel <- lm(avgValue ~ userScore, data = userTable)
}
pricePredict <- predict(userModel, userTable)
pinBargain <- round(pricePredict - userTable$avgValue)
userTable <- data.frame(userTable, pinBargain)
userTable <- userTable[,c('nameLink', 'makeAndYear', 'userScore', 'estimatedValue', 'pinBargain')]
})
output$topTables <- DT::renderDataTable({
DT::datatable(data = getUserFrame(),
colnames = c('Name', 'Make & Year', 'Your Score', 'Market Price', 'Bargain Amount($)'),
escape = 0, rownames = FALSE,
options = list(pageLength = 20, order = list(2,'desc')))
})
output$topTableExplainer <- renderText({
"The following table presents the top-scoring games based on your criteria. The Bargain Amount column is how much
of a value buy this game represents when compared to a pricing model based on your criteria. The higher the better.
Negative numbers represent games that are overpriced according to the pricing model.
Click on the Bargain Amount column to sort by best value. These tables would
be a great, low-cost way to start your collection."
})
output$summary <- renderText({
" This app was born after I read way too many 'What should I buy?' discussions on pinball forums. I figured that people
would appreciate the ability to find great tables based on what they consider most important in a game. As someone longing
to buy his first pinball machine, I also knew that people would be looking for value tables that they could get a lot of
game time out of. The data comes from the Pinside top ~250 tables. Some had to be excluded because pricing information
wasn't available."
})
}
)
我发布应用程序时没有收到任何错误或警告消息,Shiny 的应用程序日志部分也没有日志。不知道该去哪里。如果有任何帮助,我将不胜感激。
我能够解决问题。我需要将 ui.r 中的 dataTableOutput 更改为 DT::dataTableOutput。在 R 和本地浏览器中正确设置 运行 真的让我很失望,让我认为这是一个数据加载问题,而 display/output 是错误的。 MLavoie,感谢您在提交后清理代码。
我构建了一个 Shiny 应用程序,该应用程序依赖于在启动时加载本地存储的 CSV 文件。当我 运行 我电脑上的 Shiny 应用程序时,无论是在 RStudio window 还是 Google Chrome 中,应用程序都可以毫无问题地加载和显示数据。即使没有将数据加载到 R 会话中也是如此。但是,在发布应用程序后,主要数据 table 不会在启动时或点击提交按钮后显示(试图刷新 table)。
当我从使用 Shiny 的数据 table 函数切换到使用 DT 时,这个问题就开始了。我开始使用 DT 是为了能够使第一列中的名称充当链接。我目前正在开发 64 位 Macbook 运行ning Mavericks。今天刚刚在故障排除时更新了 R 和 RStudio。我也尝试从计算机 运行ning Windows 8 发布 - 数据 table 仍然没有显示在已发布的应用程序版本中。
ui.r代码:
shinyUI(fluidPage(
titlePanel("Pinball Buyer's Guide"),
sidebarLayout(
sidebarPanel(
helpText("Whether you're looking for a great value on a machine to buy or just want to find a new table you'd
like to play, this guide will help you find a table based on your tastes. Use the sliders below to
assign a weight to each category of your table ranking score. The site will use that to generate
a score for each of the available tables and to determine how much bang for your buck each table
represents."),
sliderInput('rating',
label = 'Player Ratings',
value = 1, min = 0, max = 5, step = .25),
sliderInput('game',
label = 'Game Design',
value = 1, min = 0, max = 5, step = .25),
sliderInput('art',
label = 'Art',
value = 1, min = 0, max = 5, step = .25),
sliderInput('sound',
label = 'Sound',
value = 1, min = 0, max = 5, step = .25),
sliderInput('other',
label = 'Other Game Aspects',
value = 1, min = 0, max = 5, step = .25),
sliderInput('staff',
label = 'Pinside Staff Ratings',
value = 1, min = 0, max = 5, step = .25),
helpText("Excluding the production year in the pricing model will likely push older tables
to the top of the bargain rankings. If you'd prefer a newer machine, leave this checked."
),
checkboxInput('year',
label = 'Include Machine Year in Price Model?',
value = TRUE),
submitButton('Submit')
),
mainPanel(
tabsetPanel(
tabPanel("Main",
br(),
textOutput('topTableExplainer'),
br(),
dataTableOutput('topTables'),
br()
),
tabPanel("About This App",
tags$body(textOutput('summary')),
br()
)
)
)
)
))
server.r代码:
library(DT)
pinData <- read.csv('./Data/pinDataMassaged.csv', header=TRUE, stringsAsFactors = FALSE)
userTable <- data.frame()
shinyServer(function(input, output){
getUserFrame <- reactive({
userScore <- pinData$rating * input$rating + pinData$gameDesign * input$game + pinData$artwork * input$art +
pinData$sound * input$sound + pinData$otherRating * input$other + pinData$staffRating * input$staff
userTable <- data.frame()
userTable <- data.frame(pinData, userScore)
if (input$year == 'TRUE'){
userModel <- lm(avgValue ~ userScore + age, data = userTable)
} else{
userModel <- lm(avgValue ~ userScore, data = userTable)
}
pricePredict <- predict(userModel, userTable)
pinBargain <- round(pricePredict - userTable$avgValue)
userTable <- data.frame(userTable, pinBargain)
userTable <- userTable[,c('nameLink', 'makeAndYear', 'userScore', 'estimatedValue', 'pinBargain')]
})
output$topTables <- DT::renderDataTable({
DT::datatable(data = getUserFrame(),
colnames = c('Name', 'Make & Year', 'Your Score', 'Market Price', 'Bargain Amount($)'),
escape = 0, rownames = FALSE,
options = list(pageLength = 20, order = list(2,'desc')))
})
output$topTableExplainer <- renderText({
"The following table presents the top-scoring games based on your criteria. The Bargain Amount column is how much
of a value buy this game represents when compared to a pricing model based on your criteria. The higher the better.
Negative numbers represent games that are overpriced according to the pricing model.
Click on the Bargain Amount column to sort by best value. These tables would
be a great, low-cost way to start your collection."
})
output$summary <- renderText({
" This app was born after I read way too many 'What should I buy?' discussions on pinball forums. I figured that people
would appreciate the ability to find great tables based on what they consider most important in a game. As someone longing
to buy his first pinball machine, I also knew that people would be looking for value tables that they could get a lot of
game time out of. The data comes from the Pinside top ~250 tables. Some had to be excluded because pricing information
wasn't available."
})
}
)
我发布应用程序时没有收到任何错误或警告消息,Shiny 的应用程序日志部分也没有日志。不知道该去哪里。如果有任何帮助,我将不胜感激。
我能够解决问题。我需要将 ui.r 中的 dataTableOutput 更改为 DT::dataTableOutput。在 R 和本地浏览器中正确设置 运行 真的让我很失望,让我认为这是一个数据加载问题,而 display/output 是错误的。 MLavoie,感谢您在提交后清理代码。