我有一个闪亮的应用程序,其中包含2个选项卡。在第二个选项卡中,我运行SQL查询来获取我想要在屏幕上发布的数据帧,以便用户可以看到。为了简洁起见,我只包含了相关的代码。基本上,用户选择一个日期范围,这将转到数据库并提取相关信息并将该信息返回到服务器以发布到屏幕上。运行应用程序现在,当我收到错误消息R闪亮,找不到功能
Error: could not find function "report_data"
我会感谢任何帮助您可以提供
#-----------------------------------------------------------------------------------------
# UI
# TAB 2 which lets the user select a date range and press the submit button
#-----------------------------------------------------------------------------------------
tabPanel("Review Uploaded Data",
# Side Panel with Options
fluidRow(
column(4, wellPanel(
id = "leftPanel",
div(id = "Header",
h3("Options", align = "center"),
tags$hr()
),
div(id = "form2",
dateRangeInput("dates", label = h3("Entry Date Range")),
actionButton("search", "Search Database", class = "btn-primary")
)
)),
column(8, id = "reporttable",
# Main Panel shows the uploaded excel document when a user first uploads
DT::dataTableOutput("reportTable")
)))
#-----------------------------------------------------------------------------------------
# Server
# TAB 2 Review Uploaded Data
#-----------------------------------------------------------------------------------------
# When User selects a date Range. Run the SQL to pull information for that Date Range
report_data <- observeEvent(input$search, {
load_data(input$dates)
})
# Show the summary table
output$reportTable <- DT::renderDataTable(
DT::datatable(
report_data(),
rownames = TRUE,
options = list(searching = FALSE, lengthChange = FALSE, scrollX = FALSE)
))
此功能是数据帧基础上进入到数据库,并返回功能用户选择日期范围。
# Load the data from the MYSQL table
load_data <- function(dateRange) {
# Connect to the database
db <- dbConnect(MySQL(), dbname = databaseName, host = options()$mysql$host,
port = options()$mysql$port, user = options()$mysql$user,
password = options()$mysql$password)
start_date <- dateRange[1]
end_date <- dateRange[2]
# Construct the fetching query
query <- sprintf("SELECT USER, COUNT(*) as records FROM %s
WHERE ENTRY_DATE BETWEEN '%s' AND '%s' GROUP BY 1", table, start_date, end_date)
# Submit the fetch query and disconnect
data <- dbGetQuery(db, query)
dbDisconnect(db)
names(data) <- c("User", "records")
return(data)
}
你需要'eventReactive',而不是'observeEvent'因为observeEvent - 什么也没回 – Batanichek
非常感谢你,我在这个年纪里挠了挠头。请把它作为答案,我会立即标记它 –