r - R/Shiny 直方图类作为反应性
问题描述
R 允许将直方图保存为“直方图”类对象:
h <- hist(x,plot=FALSE)
并且可以从“h”恢复几个值。例如“h$mids”、“h$counts”等...
现在,我需要在 Shiny 脚本中使用它,但我找不到如何将“h”保存为反应变量。你知道怎么做吗?
我试过: h <- reactive({hist(x,breaks=y,plot=FALSE)})
但它不起作用。
以下是我的脚本。
谢谢
胡安
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()) })
推荐阅读
- kubernetes - Kubernetes Flannel k8s_install-cni_kube-flannel-ds 在工作节点上退出
- aspnetboilerplate - 问题:可以在未经授权的情况下使用 Angular 版本吗?
- jquery - 我有一个带有多个复选框和选择选项的表单。如果单击复选框,我想启用选择选项
- php - 如何在最后一条记录的一周内对列求和?
- json - AppleScript,复制文件
- javascript - 为什么行的顺序在这里很重要?
- python - 如何为 keras.VGG19 预处理图像?
- javascript - 如何将箭头函数迭代限制为 10 个数据?
- red - 如何将数据附加到 R/S 中的块?
- firebase - React Native - 使用 Firebase 上传图片