【发布时间】:2018-05-24 20:38:29
【问题描述】:
R 允许将直方图保存为“直方图”类对象:
h
并且可以从“h”中恢复几个值。例如 “h$mids”、“h$counts”等...
现在,我需要在 Shiny 脚本中使用它,但我找不到 如何将“h”保存为反应变量。你知道怎么 这样做?
我试过:h
但它不起作用。
以下是我的脚本。
谢谢
胡安
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变量没有问题:output$hist_data <- renderPrint({ h() }) -
感谢瑞恩的建议。有用。现在可以通过以下方式恢复变量:counts