Невозможно обновить ggplot при изменении значений rhandsontable в блестящем приложении
Я создал простое блестящее приложение, в котором используются яркие и блестящие пакеты. Моя проблема в основном на третьей вкладке "Результаты алгоритма". Там у меня есть rhandsontable
и я создал простой сюжет на основе DF
а также df1
наборы данных. Проблема в том, что после создания начального графика я не могу обновить его, когда я вручную обновляю значения таблицы. Он отвечает только тогда, когда я выбираю другой алгоритм из моего selectinput.
PS: Вам не нужно загружать CSV-файл для работы, но вам нужно нажать кнопку отправки, чтобы создать график.
library(shiny)
library(ggplot2)
library(rhandsontable)
library(DT)
library(data.table)
library(tidyr)
fluidPage(
# App title ----
titlePanel(div("CASE STUDY - Replication of CANARY",style = "color:blue")),
# Sidebar layout with input and output definitions ----
sidebarLayout(
# Sidebar panel for inputs ----
sidebarPanel(
# Input: Select a file ----
fileInput("file1", "Input CSV-File",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
# Horizontal line ----
tags$hr(),
# Input: Checkbox if file has header ----
checkboxInput("header", "Header", TRUE),
# Input: Select separator ----
radioButtons("sep", "Separator",
choices = c(Comma = ",",
Semicolon = ";",
Tab = "\t"),
selected = ","),
# Input: Select quotes ----
radioButtons("quote", "Quote",
choices = c(None = "",
"Double Quote" = '"',
"Single Quote" = "'"),
selected = '"'),
# Horizontal line ----
tags$hr(),
# Input: Select number of rows to display ----
radioButtons("disp", "Display",
choices = c(Head = "head",
All = "all"),
selected = "head"),
tags$hr(),
tags$hr(),
htmlOutput("alg")
),
# Main panel for displaying outputs ----
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Table", tableOutput("contents")),
tabPanel("Plots"
),
tabPanel("Algorithm Results",
rHandsontableOutput("hot"),
plotOutput("plot13"),
submitButton(text = "Apply Changes", icon = NULL, width = NULL)
)
)
)
)
)
server.r
function(input, output) {
#mini file
df1 <- data.frame(col1 = rnorm(20),
col2 = rnorm(20))
DF = data.frame(ALGORITHMS=c("Algorithm 1","Algorithm 2", "Algorithm 3"), ParA = c(0,0,0), ParB = rnorm(3),
ParC = rnorm(3), ParD = rnorm(3))
output$hot <- renderRHandsontable({
rhandsontable(DF[DF$ALGORITHMS%in%input$alg,], width = 550, height = 300) %>%
hot_col("ParA", format = "0.0") %>%
hot_col("ParB", format = "0.0") %>%
hot_col("ParC", format = "0.0") %>%
hot_col("ParD", format = "0.0")
})
csvdata <- c(1,2,3,4)
output$contents <- renderTable({
# input$file1 will be NULL initially. After the user selects
# and uploads a file, head of that data file by default,
# or all rows if selected, will be shown.
req(input$file1)
csvdata <- read.csv(input$file1$datapath,
header = input$header,
quote = input$quote)
if(input$disp == "head") {
return(head(csvdata))
}
else {
return(csvdata)
}
})
output$alg<-renderUI({
selectInput("alg","Select Algorithm",choices = as.character(unique(DF$ALGORITHMS)),selected = "Algorithm 1",multiple =T)
})
output$plot13<- renderPlot({
df1$col <- cut(df1[,2],
breaks = c(-Inf, DF[DF$ALGORITHMS%in%input$alg,][1,2], Inf),
labels = c("<=2", ">2"))
ggplot(df1, aes(x = df1[,1], y = df1[,2],color = col )) +
geom_point()
})
}