我有一個可以生成圖表和數據表的Shiny應用程序,圖表上的y軸鏈接到表列中的最大值通過一些用戶輸入過濾。我希望這個相同的值是sliderInput的最大值,所以它會是動態的,因爲每當用戶在下拉列表中選擇其他內容時,值都會改變。將最大sliderInput值鏈接到表列中的最大值
表格基於下拉列表進行過濾,表格內有一個名爲「價格指數」的列。例如,如果用戶選擇「麪包」,我希望最大sliderInput值根據表格中「價格指數」列的最大值進行更改。
這是我的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
任何幫助深表感謝。
謝謝!我微調了一下: 'as.integer(max(unlist(pricing_data [section_lower == input $ subsec,。('Price Index')])))'' – MidnightDataGeek