[英]Shiny R “ERROR: non-numeric argument to binary operator” while trying to pass a variable from server to ui
顯然在這里做錯了什么或做得不夠。 我需要使用正在上傳的.xlsx 數據中的一列來設置sliderInput
的min
、 max
和value
。
用戶界面
ui <- dashboardPage(
dashboardHeader(title = "test"),
dashboardSidebar(sidebarMenu(
sliderInput(
"man",
"Time Interval",
min = min("time"),
max = max("time"),
value = c(min("time"), max("time"))
)
)),
dashboardBody(
wellPanel(
fileInput("file", "Choose XLSX File"),
downloadButton("downloadReport", "Generate Report")
),
textOutput("time"),
box(
title = "Position",
width = "100%",
plotOutput("plot1", height = 450)
)
)
)
服務器
server <- function(input, output) {
my_data <- reactive({
inFile <- input$file
if (is.null(inFile))
return(NULL)
dataRaw <- read.xlsx(inFile$datapath)
})
output$plot1 <- renderPlot({
if (is.null(my_data()))
return(NULL)
str(my_data())
plot(my_data()$Position.X,
my_data()$Position.Y,
xlab = "Distance (X)",
ylab = "Distance (Y)")
})
output$time <- reactive({
if (is.null(my_data()))
return(0)
my_data()$Time
})
}
文件https://drive.google.com/drive/folders/1wObfHrFz2hMg3M5xfANzCuHwvpc6wKbi?usp=sharing
錯誤
錯誤:二元運算符的非數字參數
錯誤發生在行
min = min("time"),
max = max("time"),
value = c(min("time"), max("time"))
但線
textOutput("time"),
確實得到了變量time
。
我已經共享了文件和輸入數據。 謝謝!
使用renderUI
解決它,如Get min max of sliderInput in shiny
在我的 ui.R 代碼中,我將sliderInput(...)
部分替換為uiOutput("slider")
並在 server.R 中將output$time <- reactive({...})
部分替換為:
output$slider <- renderUI({
if (is.null(my_data()))
sliderInput("slider",
"",
min = 0,
max = 0,
value = c(0, 0))
maxkaw <- max(my_data()$Time)
minkaw <- min(my_data()$Time)
sliderInput(
"slider",
"Min-Max",
min = minkaw,
max = maxkaw,
value = c(minkaw, maxkaw)
)
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.