【发布时间】:2017-06-28 21:10:33
【问题描述】:
我有一个 Shiny 应用程序,它生成一个图表和一个数据表,图表上的 y 轴链接到由一些用户输入过滤的表格列中的最大值。我希望这个相同的值成为滑块输入上的最大值,因此它是动态的,因为每次用户在下拉列表中选择其他内容时,该值都会改变。
根据下拉列表过滤表格,表格中有一个名为“价格指数”的列。例如,如果用户选择“面包”,我希望最大滑块输入值根据表中“价格指数”列的最大值进行更改。
这是我的 Shiny 代码减去位于服务器函数之上的函数。
server <- function(input, output, session) {
output$priceplot <- renderPlot(
{
Price_Score(input$s_ranks[1], input$s_ranks[2], input$s_index[1], input$s_index[2], input$subsec)
}
)
output$table <- DT::renderDataTable(
DT::datatable(
pricing_data[pricing_data$section_lower == input$subsec]
)
)
session$onSessionEnded(
function() {
stopApp()
}
)
onSessionEnded = function(callback) {
return(.closedCallbacks$register(callback))
}
}
####
ui <- fluidPage(
titlePanel("Price Score Optimisation"),
fluidRow(
column(3,
wellPanel(
h4("Filters"),
sliderInput("s_index", "Select Price Index Values",
0, 350, c(0, 50), step = 10),
sliderInput("s_ranks", "Select ranks", 0, 22000, value = c(1000, 15000)),
selectInput(
"subsec",
"Subsections",
choices = unique(as.character(pricing_data$section_lower)),
selected = TRUE,
multiple = FALSE,
selectize = FALSE
)
)
),
column(9,
plotOutput("priceplot")
)
),
fluidRow(DT::dataTableOutput("table")
)
)
shinyApp(ui = ui, server = server)
我在服务器函数中尝试了这个,但在控制台中出现错误:
observe({
val <- max(DT::datatable(
pricing_data[pricing_data$section_lower == input$subsec, .(`Price Index`)][1])
)
# Control the value, min, max, and step.
# Step size is 2 when input value is even; 1 when value is odd.
updateSliderInput(session, "s_index",
min = 0, max = val+50, step = 10)
})
错误是Warning: Error in max: invalid 'type' (list) of argument
非常感谢任何帮助。
【问题讨论】: