【发布时间】:2015-12-17 10:22:08
【问题描述】:
我对 R 很陌生,这是我第一次尝试 Shiny,所以请原谅可能是明显的修复。
我有以下数据框:
ID Bet.Total Point.Total Cash.Value
1 2000 5,741.00 43,264.00 61.81
2 2001 10,009.70 90,087.00 128.70
3 2002 10,875.06 97,177.00 138.82
4 2003 5,754.04 43,658.00 62.37
5 2004 5,771.00 43,860.00 62.66
6 2005 5,097.70 38,743.00 55.35
7 2006 1,605.45 59,402.00 84.86
8 2007 7,430.43 55,995.00 79.99
9 2008 20,960.50 188,645.00 269.49
10 2009 10,626.80 92,209.00 131.73
11 2010 42,711.50 384,404.00 549.15
我正在尝试创建一个闪亮的应用程序,用户可以在其中选择他们的 ID,并且该应用程序返回他们的 Bet.Total、Point.Total 和 Cash.Value。
这是我的 ui.R 代码:
library(shiny)
shinyUI(fluidPage(
titlePanel("Bet Rewards Calculator"),
fluidRow(
column(3,
selectizeInput("ID", choices = "ID",
label = h4("Rewards ID")),
br(),
actionButton("submit", "Submit")),
column(7, offset = 2,
DT::dataTableOutput("betReport")))
)
)
这是我的 server.R 代码: 图书馆(DT)
betReport <- read.csv("BetReport.csv")
shinyServer(function(input, output) {
observeEvent(input$submit)
output$x1 <- DT::renderDataTable({betReport})
# print the selected indices
output$x2 = renderPrint({
s = input$ID_rows_selected
if (length(s)) {
cat("This is your balance.")
cat(s, sep = ",")
}
})
})
我尝试了从简单到复杂的服务器代码的各种排列以仅返回相应的数据行,但没有成功。当我运行此特定代码时,应用程序崩溃并收到以下错误消息:Error in exprToFunction(handlerExpr, handler.env, handler.quoted) :
argument "expr_sub" is missing, with no default
任何想法/建议将不胜感激!
【问题讨论】:
-
有很多问题。在
server.R中出现x1、x2和ID_rows_selected,它们不会出现在ui.R中。betReport输出未定义。不清楚用户可以在哪里选择他/她的ID,因为selectInput的choices参数只有一个值。