我有一個閃亮的應用程序,其中包含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
非常感謝你,我在這個年紀裏撓了撓頭。請把它作爲答案,我會立即標記它 –