R 正在尝试从应用程序中的数据表中提取特定行
我对R非常陌生,这是我第一次尝试闪亮,所以请原谅这可能是一个明显的修复 我有以下数据框:R 正在尝试从应用程序中的数据表中提取特定行,r,shiny,R,Shiny,我对R非常陌生,这是我第一次尝试闪亮,所以请原谅这可能是一个明显的修复 我有以下数据框: 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
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")))
)
)
这是我的服务器。R代码:
图书馆(DT)
betReport我不完全确定你希望你的应用程序做什么,所以我很有信心下面的解决方案不会让你完全达到你的目标,但我认为应该很接近
您得到的错误来自server.R
文件中的observeEvent(输入$submit)
。它需要在触发事件时触发的第二个参数,而您没有指定任何内容。在下面的代码中,我刚刚将所有内容都包含在您的服务器代码中,我认为这不是您想要的,只是给您一个示例
此外,在ui.R
文件中,您需要为每个元素设置标签,这些标签对应于在server.R
文件中计算的输出元素。选择也很无聊,因为现在只有一个可能的选择(ID)
但是,以下两个文件可能会帮助您启动并运行。至少它会显示数据表并响应输入
第一个是server.R
。记住在数据中包含要读取的行以及所有这些内容
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 = ",")
} else {
print("I shouldn't be here but the rows_selected is wrong")
}
})
})
})
有许多问题。在server.R
中出现x1
,x2
和ID\u选中的行,这些行不显示在ui.R
中。未定义betReport
输出。由于selectInput
的choices
参数只有一个值,因此不清楚用户可以在何处选择其ID
。
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 = ",")
} else {
print("I shouldn't be here but the rows_selected is wrong")
}
})
})
})
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("x1"),
br(),
textOutput("x2")
)
)
)
)