【问题标题】:Error: Expected an object with class 'shiny.tag' when trying to output renderValueBox错误:在尝试输出 renderValueBox 时需要一个具有“shiny.tag”类的对象
【发布时间】:2020-04-22 04:29:27
【问题描述】:

R 和 R Shiny 的新手。我的目标是通过 valueBoxOutput 输出列的最大值,而当用户更改过滤器(例如日期等)时,该值能够更新。我收到错误:预期具有类 'shiny.tag' 的对象,我不知道这意味着什么,我看不出代码错误的原因。

ui.R

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,尽管它显然存在,这令人沮丧。

希望有人能提供帮助并指出我可能犯的一个明显错误。 谢谢

【问题讨论】:

  • 你找到问题了吗?您没有收到很多回复的原因之一是您的代表不够短。

标签: r shiny shinydashboard reactive


【解决方案1】:

不确定是否要在此行末尾使用管道:

maxsales1 <- max(maxsales$Ordered_Product_Sales)%>%

【讨论】:

    【解决方案2】:

    您的问题可能出在这条服务器线路上:

    maxsales1 &lt;- max(maxsales$Ordered_Product_Sales)%&gt;% valueBox(value =maxsales1,subtitle = "Maximum Sales Value")

    移除管道%&gt;%,它应该可以工作。

    })

    【讨论】:

      猜你喜欢
      • 2019-04-15
      • 2019-03-31
      • 1970-01-01
      • 2017-08-06
      • 1970-01-01
      • 2014-02-28
      • 1970-01-01
      • 1970-01-01
      • 2021-03-19
      相关资源
      最近更新 更多