0
ユーザーが定義する散布図に2つの変数の適合順をユーザーが定義できるようにするアプリがあります。今、私の試みはエラーError in x - xbar : non-numeric argument to binary operator
で失敗したことを証明しています。私はこれを修正する方法については犠牲になっており、この作業をどのようにするかについての提案は高く評価されています。ggvisプロットへのユーザー定義フィット
ui <- fluidPage(
selectInput(inputId = "x", label="Select x-axis Variable:", choices=as.character(names(mtcars)),selected='mpg', multiple = FALSE),
selectInput(inputId = "y", label="Select y-axis Variable:", choices=as.character(names(mtcars)),selected='hp', multiple = FALSE),
numericInput(inputId = "order", label = "Select Order of fit line", value = 2, min = 1, max = 6, step = 1),
ggvisOutput("plot1")
)
server<-function(input,output,session)
{
vis <- reactive({
xvar <- prop("x", as.symbol(input$x))
yvar <- prop("y", as.symbol(input$y))
mtcars %>%
ggvis(x = xvar, y = yvar) %>%
layer_points() %>%
layer_model_predictions(model = "lm", formula=yvar ~ poly(xvar,input$order))
})
vis %>% bind_shiny("plot1")
}
shinyApp(ui = ui, server = server)
私が思いつくのは、一緒に数式を貼り付け、 'as.formula'を使うことです。これには、選択した変数を直接使用することが含まれます。例えば、 'xvar'の代わりに' input $ x'を使用します。式をas.formula(paste $ y、 "〜"、 "poly"、$ x、 "、"、$ order、 ")")) ' – aosmith
に入力します。答え私はそれを正しいものとして受け入れる – User247365