R allows to save histograms as "histogram" class objects:
h <- hist(x,plot=FALSE)
and several values can be recovered from "h". For instance "h$mids", "h$counts" etc ...
Now, I need to use this in a Shiny script but I can't find how to save "h" as a reactive variable. Do you know how to do that?
I tried: h <- reactive({hist(x,breaks=y,plot=FALSE)})
but it doesn't work.
The following is my script.
Thanks
Juan
library(shiny)
InputParameters <- function(u) {
sidebarPanel("Input parameters"
,numericInput("N","Number",1000,min=100,max=10000,step=100,width=NULL)
,numericInput("mc","Mean",0.22,min=0.02,max=0.5,step=0.02,width=NULL)
,numericInput("sc","Sttdev",0.57,min=0.4,max=0.8,step=0.01,width=NULL)
,numericInput("logmstep","Bin",0.2,min=0.1,max=0.5,step=0.1,width=NULL)
,width=2)
}
ui <- fluidPage(
sidebarLayout(
InputParameters("A"),
mainPanel(
navbarPage("IMF2CMD"
,tabPanel("System-IMF"
,plotOutput("plot1",width="100%",height="700px",click=NULL,
dblclick=NULL,hover=NULL,hoverDelay=NULL,
hoverDelayType=NULL,brush=NULL,clickId=NULL,hoverId=NULL,
inline=FALSE)
)
)
)
)
)
server <- function(input,output,session) {
logmc <- reactive( { log(input$mc,10) } )
logm <- reactive( { rnorm(input$N,logmc(),input$sc) } )
breakslogM <- reactive( { breakslogM <- seq(-3,2,input$logmstep) } )
output$plot1 <- renderPlot( { hist(logm(),breaks=breakslogM(),plot=TRUE) })
h <- reactive( { hist(logm(),breaks=breakslogM(),plot=FALSE) } )
}
shinyApp(ui=ui,server=server)
它与您的h <- reactive( { hist(logm(),breaks=breakslogM(),plot=FALSE) } )
,然后output$plot1 <- renderPlot( { plot(h()) })
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.