1
votes

Problem:

The graph plot does not Render. There are no errors.

Description:

Even though I do not use a reactive value below, it should work because it is within an observed event. Rendering a table works perfectly fine.

Additional Info

The AllElements Data is definitely populated! I printed them out to check. They are vectors of type double.

library(shiny)
library(shinyWidgets)
library(shinythemes)
library(datasets)

shinyApp(
  ui = navbarPage(
    "Real Time Instruments",
    #############################    Page 1     #############################
    tabPanel("Training",

             mainPanel(

               actionButton("analyse", "Train Model", width = "100%")

             )
             #############################    Page 2     #############################
    ),
    tabPanel("Results",

               tableOutput ( "error"),
               plotOutput("predict_plot", inline = TRUE)

    )
  ),
  server = function(input, output, session) {

    ### Analyse the data
    analyse <- observeEvent(input$analyse , {

      # Run the Analysis
      AllElements <- data.frame( x = 1:10 )

      # populate the results
      populateResults (AllElements)
    })

    #### Results Page ####
    populateResults <- function (allElements) {

      # First the error table
      output$error <- renderTable(allElements$error_sd, digits = 5) ## <--- THIS WORKS!!!

      # Second Plots
      # par(mar = rep(2, 4)) # Might be needed

      x <- allElements$x
      xlab <- allElements$x
      y <- allElements$x
      ylab <- allElements$x

      # Plot Predict Var
      output$predict_plot <- renderPlot({plot (x, y)}) # <--- THIS DOESN'T WORK!!!

    }
  })
  }
)
1
Please provide a reproducible example. The mistake could also be in the UI. So please share the code for an app. You also didn't describe what exactly doesn't work. Is there no plot? Is an error message displayed?Felix Grossmann
@FelixGrossmann Updated.RickyTamma
I updated your code. It did not work for me because of missing brackets and some commas. After all it still does not work because there is no AnalyseData available.Felix Grossmann
@FelixGrossmann I echanged it with dummy data. it should work nowRickyTamma

1 Answers

1
votes

I had to change several things in your code.

  • I transformed the data into an eventReactive
  • I didn't use your function populateResults and replaced it by independent render functions
  • I added a column error_sd to the example dataset so that it can be found later in the render functions
  • I don't know if I missed something here, just have a look at my code.

This example works for me:

library(shiny)
library(shinyWidgets)
library(shinythemes)
library(datasets)

shinyApp(
  ui = navbarPage(
    "Real Time Instruments",
    tabPanel("Training",

         mainPanel(

           actionButton("analyse", "Train Model", width = "100%")

         )
),
tabPanel("Results",

         tableOutput ( "error"),
         plotOutput("predict_plot")

) 
),
 server = function(input, output, session) {

analyse <- eventReactive(input$analyse , {
  output <- data.frame( x = 1:10 , error_sd = 1:10)
  return(output)
})

output$error <- renderTable({
  analyse()$error_sd} , digits = 5
)

output$predict_plot <- renderPlot({
  # x <- allElements$x
  # xlab <- allElements$x
  # y <- allElements$x
  # ylab <- allElements$x

  plot(analyse()$x, analyse()$x)
})
})