r - Shiny renderPlot does not work -
problem:
the graph plot not render. there no errors.
description:
even though not use reactive value below, should work because within observed event. rendering table works fine.
additional info
the allelements data populated! printed them out check. 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 data analyse <- observeevent(input$analyse , { # run analysis allelements <- data.frame( x = 1:10 ) # populate results populateresults (allelements) }) #### results page #### populateresults <- function (allelements) { # first error table output$error <- rendertable(allelements$error_sd, digits = 5) ## <--- works!!! # second plots # par(mar = rep(2, 4)) # might needed x <- allelements$x xlab <- allelements$x y <- allelements$x ylab <- allelements$x # plot predict var output$predict_plot <- renderplot({plot (x, y)}) # <--- doesn't work!!! } }) } )
i had change several things in code.
- i transformed data
eventreactive
- i didn't use function
populateresults
, replaced independent render functions - i added column
error_sd
example dataset can found later in render functions - i don't know if missed here, have @ code.
this example works 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) }) })
Comments
Post a Comment