Ggplot not updated when i manually update the values of rhandsontable in shiny app

ggplot2
shiny
datatable

#1

i have created a simple shiny app which uses rhandsontable and shiny packages. My problem is mainly the third tab “Algorithm Results”. There i have an rhandsontable and i create a plot based on it and the DF dataset. The problem is that after creating the initial plot i cannot UPDATE it when i manually UPDATE the values of the table. It only responds only when i choose a different algorithm from my selectinput. P.S.:You do not have to load csv file to work.

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()
  })
    
    
    
    
}

#2

I attempted to run your application, but your example code above is missing the plot you are trying to create, as well as the selectInput for the algorithm choice. If you update with those two things we can look at solving the issue.


#3

I fixed.Seems to work now. Check it out and tell me what you think. Press the submit button to create the plot.


#4

Have you tried again with this?