r - 错误:在尝试输出 renderValueBox 时需要一个具有“shiny.tag”类的对象
问题描述
R 和 R Shiny 的新手。我的目标是通过 valueBoxOutput 输出列的最大值,而当用户更改过滤器(例如日期等)时,该值能够更新。我收到错误:预期具有类“shiny.tag”的对象,我不知道这意味着什么,我也看不出代码错误的原因。
用户界面
library(shinythemes)
library(shiny)
library(plotly)
library(lubridate)
library(shinydashboard)
ui <- dashboardPage(skin = "black",
dashboardHeader(title = "Metric Tracker")
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "Dashboard", icon = icon("city")),
dashboardBody(fluidRow(
tabItems(
tabItem(tabName = "Dashboard",
box(collapsible = TRUE, title = "All Brands",status = "info",solidHeader = TRUE, width = 8, plotlyOutput("valuePlot", height = "500px"), plotlyOutput("testplot", height = "500px")),
box(width = 4,title = "Inputs", solidHeader = TRUE, status = "warning", selectInput("value", "1st Value to Track:" , choices = c("Units_Ordered", "Buy_Box_Percentage", "Ordered_Product_Sales", "Session_Percentage","aov"), selected = "Ordered_Product_Sales", multiple = FALSE, selectize = TRUE),
selectInput("value2", "2nd Value to Track:" , choices = c("Units_Ordered", "Buy_Box_Percentage", "Ordered_Product_Sales", "Session_Percentage","aov"), selected = "Units_Ordered", multiple = FALSE, selectize = TRUE),
selectInput("marketplace", "Select Marketplace", choices = c("UK","DE","FR","IT","ES")),
sliderInput("date", "Date Range:", min = as.Date("2019-07-06","%Y-%m-%d"), max = as.Date("2019-10-26","%Y-%m-%d"), value = c(as.Date( "2019-07-06"),as.Date( "2019-10-26")),step = 7, timeFormat = "%Y-%m-%d")),
valueBoxOutput("max", width =3), valueBoxOutput("min", width = 3)
),
服务器(我只包括我的代码的相关部分,所以如果你相信它可能会在其他地方造成干扰,请告诉我,但要知道其他一切都很好)
server <- function(input, output){
output$max <- renderValueBox({
maxsales <- filter(metricx2, Date >= input$date[1] & Date <= input$date[2] & Marketplace %in% input$marketplace)
maxsales1 <- max(maxsales$Ordered_Product_Sales)%>%
valueBox(value =maxsales1,subtitle = "Maximum Sales Value")
})
output$min <- renderValueBox({
valueBox(
value = min(metricx2$Ordered_Product_Sales),
subtitle = "Minimum Sales Value"
)
})
}
shinyApp(ui = ui, server = server)
metricx2 是我要从中提取的数据框。“Min”部分有效,但对用户的输入没有反应。此外,R 有时会提示我在渲染中输入反应函数。然而,这对我不起作用。此外,R 很难找到 Ordered_Product_Sales,尽管它显然在那里令人沮丧。
希望有人可以帮助并指出我可能犯的一个明显错误。谢谢
解决方案
不确定您是否希望管道位于此行的末尾:
maxsales1 <- max(maxsales$Ordered_Product_Sales)%>%