sliderInput控制的随机样本和

sliderInput控制的随机样本和,r,ggplot2,rstudio,shiny,R,Ggplot2,Rstudio,Shiny,唯一的问题是示例没有对excel文件中的净返回列求和,这会随着sliderInput而更改。我尝试使用sum和summary,但没有得到结果。事实上,如果没有scale_y_continuous breaks函数,它会绘制一系列值(这就是我知道它没有做我想要的事情的原因)。感谢您的帮助!谢谢 用户界面: 服务器: server = function(input, output) { output$filter = renderPlot({ mysample = filtered[samp

唯一的问题是示例没有对excel文件中的净返回列求和,这会随着sliderInput而更改。我尝试使用sum和summary,但没有得到结果。事实上,如果没有scale_y_continuous breaks函数,它会绘制一系列值(这就是我知道它没有做我想要的事情的原因)。感谢您的帮助!谢谢

用户界面:

服务器:

server = function(input, output) {
  output$filter = renderPlot({
  mysample = filtered[sample(1:nrow(filtered), input$obs,
                            replace=FALSE),]
  mysample2 = unfiltered[sample(1:nrow(unfiltered), input$obs,
                                replace=FALSE),]
  tbl = bind_rows(Filtered = mysample, Unfiltered = mysample2,
                  .id="type")
  #sum(mysample)
  #sum(mysample2)
  #summarise(mysample = sum(mysample),
  #          mysample2 = sum(mysample2))

  ggplot(tbl, aes(x = type, fill = type)) +
    geom_col(aes(y = Net_Return)) +
    labs(x = "Type", y = "Net Return") +
    theme_bw() +
    theme(legend.position = "none") +
    scale_y_continuous(labels = scales::dollar, limits = c(0, 2500000))  
 })
}  

我们需要一个
分组依据
总和

library(ggplot2)
library(shiny)
library(dplyr)

ui = fluidPage(
  sliderInput("obs", "Number of Observations", value = 550, min = 1, max = 10),
  plotOutput("filter")
)    
filtered <- mtcars[1:15,]
unfiltered <- mtcars

server = function(input, output) {
  output$filter = renderPlot({
    mysample = filtered[sample(1:nrow(filtered), input$obs,
                               replace=FALSE),]
    mysample2 = unfiltered[sample(1:nrow(unfiltered), input$obs,
                                  replace=FALSE),]
    tbl = bind_rows(Filtered = mysample, Unfiltered = mysample2,
                    .id="type") %>%
                    group_by(type) %>%
                    summarise(wt = sum(wt))

    print(nrow(tbl))
    print(tbl)
    #sum(mysample)
    #sum(mysample2)
    #summarise(mysample = sum(mysample),
    #          mysample2 = sum(mysample2))

    ggplot(tbl, aes(x = type,  fill = type)) +
      geom_col(aes(y =wt)) +
      labs(x = "Type", y = "Weight") +
      theme_bw() +
      theme(legend.position = "none") 
  })
}  
shinyApp(ui, server)
库(ggplot2)
图书馆(闪亮)
图书馆(dplyr)
ui=fluidPage(
滑块输入(“obs”,“观察次数”,值=550,最小值=1,最大值=10),
打印输出(“过滤器”)
)    
过滤%
总结(wt=总和(wt))
打印(nrow(待定))
打印(待定)
#总和(我的样本)
#总和(样本2)
#总结(mysample=sum(mysample),
#mysample2=总和(mysample2))
ggplot(tbl,aes(x=类型,填充=类型))+
几何坐标(aes(y=wt))+
实验室(x=“类型”,y=“重量”)+
主题_bw()+
主题(legend.position=“无”)
})
}  
shinyApp(用户界面、服务器)
-输出


谢谢!正是我需要的
library(ggplot2)
library(shiny)
library(dplyr)

ui = fluidPage(
  sliderInput("obs", "Number of Observations", value = 550, min = 1, max = 10),
  plotOutput("filter")
)    
filtered <- mtcars[1:15,]
unfiltered <- mtcars

server = function(input, output) {
  output$filter = renderPlot({
    mysample = filtered[sample(1:nrow(filtered), input$obs,
                               replace=FALSE),]
    mysample2 = unfiltered[sample(1:nrow(unfiltered), input$obs,
                                  replace=FALSE),]
    tbl = bind_rows(Filtered = mysample, Unfiltered = mysample2,
                    .id="type") %>%
                    group_by(type) %>%
                    summarise(wt = sum(wt))

    print(nrow(tbl))
    print(tbl)
    #sum(mysample)
    #sum(mysample2)
    #summarise(mysample = sum(mysample),
    #          mysample2 = sum(mysample2))

    ggplot(tbl, aes(x = type,  fill = type)) +
      geom_col(aes(y =wt)) +
      labs(x = "Type", y = "Weight") +
      theme_bw() +
      theme(legend.position = "none") 
  })
}  
shinyApp(ui, server)