R闪亮的新手。当我尝试使用反应性函数实现valueBox时,反应性函数会根据用户的选择,根据列名的选择而更改为我想从所选列中产生最大值的位置。如果找不到对象“ Ordered_Product_Sales”,尽管出现了一系列错误,但显然无法应用非函数。
这是我的代码
library(shinythemes)
library(shiny)
library(plotly)
library(lubridate)
library(shinydashboard)
library(shinyWidgets)
ui <- dashboardPage(skin = "black", #theme = shinytheme("cyborg"),
dashboardHeader("Metric Tracker"),
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "Dashboard", icon = icon("city"))))
dashboardBody(fluidRow(
tabItems(
tabItem(tabName = "Dashboard",
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)
valueBoxOutput("max"), valueBoxOutput("min", width = 3)
),
server <- function(input, output){
g <- reactive({
(input$value)
})
output$max <- renderValueBox({
#maxi <- max(metricx2[,get(g())])
valueBox(maxi, subtitle = "Max")
我只是想显示在selectInput中选择的列中的最大值。反应式在列名/ selectInput选项之间切换。Metricx2是我要从中提取最大值的数据。
如果您需要其他代码,请告诉我,因为这只是一小段,我本可以省略一些有用的信息。
感谢您的帮助,我正在尝试。
您没有给我显示足够的代码来查看问题所在。这是一个最小的工作示例:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Dynamic boxes"),
dashboardSidebar(
selectInput('column', 'Column:', names(mtcars))
),
dashboardBody(
valueBoxOutput("vbox")
)
)
server <- function(input, output) {
output$vbox <- renderValueBox({
valueBox(
paste('Maximum of', input$column),
max(mtcars[[input$column]])
)
})
}
shinyApp(ui, server)