#r #shiny #rhandsontable
Вопрос:
Привет, я пытаюсь создать блестящее приложение, которое служит пользователям для обновления ячеек таблицы. это возможно с помощью rhandsontable, тогда в фоновом режиме существует модель, которая предсказывает в соответствии с новыми обновлениями данных и показывает ее в качестве дополнительного столбца под названием «Прогноз» в данных. Я могу легко построить динамическую таблицу данных с помощью rhandsontable, но не могу использовать ее для прогнозирования в реальном времени. Вот что и как я пытался сделать.
library(shiny)
library(rhandsontable)
library(tidyverse)
library(ggplot2)
ui <- fluidPage(
mainPanel(
rHandsontableOutput("table"),
plotOutput("plot1")
)
)
server <- function(input, output, session) {
mtcars %>%
select(cyl,hp,carb,mpg) %>%
head(10) -> data1
model1 <- lm(mpg~cyl hp carb, data = data1)
#colnames(data1)[4] <- "Prediction"
output$table <- renderRHandsontable({
rhandsontable(data1) %>%
hot_col("cyl", type = "dropdown", source = as.character(sort(unique(mtcars$cyl))), default = "4") %>%
hot_col("hp", type = "dropdown", source = as.character(sort(unique(mtcars$hp))), default = "123") %>%
hot_col("carb", type = "dropdown", source = as.character(sort(unique(mtcars$carb))), default = "2") %>%
hot_col('Prediction')
})
print(predict(model1,hot_to_r(input$table)))
#preds<-predict(model1, hot_to_r(input$table))
#data1$Prediction <- preds
xax1<-1:10
output$plot1 <- renderPlot({
data3 <- hot_to_r(input$table)
preds<-predict(model1, data3)
#print(preds)
#print("--------------------------")
ggplot() geom_col(aes(x=xax1, y=preds))
#plot(xax1, preds, type = "h", lwd=4)
})
}
shinyApp(ui, server)
любая помощь приветствуется, заранее спасибо.