R|设置一个可编辑的数据框,以便以后能够进行绘图

R|设置一个可编辑的数据框,以便以后能够进行绘图,r,dataframe,shiny,reactive,R,Dataframe,Shiny,Reactive,我正在尝试根据sliderInput的输出设置一个数据帧 这是我的密码: runApp( list( ui = dashboardPage( dashboardHeader(title = "Crédit"), dashboardSidebar( sidebarMenu( menuItem("Visualisation des données", tabName = "vis

我正在尝试根据sliderInput的输出设置一个数据帧

这是我的密码:

runApp(
  list(
    ui = dashboardPage(
      dashboardHeader(title = "Crédit"),
      dashboardSidebar(
        sidebarMenu(
          menuItem("Visualisation des données", tabName = "visualization", icon = icon("poll"))
        )),
      dashboardBody(
        tabItems(
          # visualization
          tabItem(tabName = "visualization",
                  h1("Visualisation des données"),
                  h2("Exploration du tableau"),
                  dataTableOutput('dataTable'),
                  h2("Graphiques"),
                  fluidRow(
                    column(5, plotOutput("Plot1")),
                    column(4,dateRangeInput("dates", label = h3("Date range"),
                                            start = as.Date("1972-09-30"))
                       ),
                    column(4,
                           sliderInput("slider", label = h3("Slider"), min = 0, 
                                       max = 5, value = 1, step = 0.5),
                    column(6,
                          dataTableOutput('my_table')
                    )))
          )
        )))
    , server = function(input, output) {
      myReactives <- reactiveValues(credit = Credit_Defaut)
      output$dataTable = DT::renderDataTable(Credit_Defaut[1:100,])
      a <- reactive({as.data.frame(matrix(data = NA, nrow = (length(seq(0,10,input$slider))-1), ncol = 1))})
      b <- reactive({as.data.frame(matrix(data = NA, nrow = (length(seq(0,10,input$slider))-1), ncol = 1))})
      df <- reactive({as.data.frame(matrix(data = c(paste0("[", seq(0,10,input$slider)[1],";",seq(0,10,input$slider)[2],"]"),
                                                    for (i in 2:(length(seq(0,10,input$slider))-2)){
                                                      a()[i-1] <- paste0("]", seq(0,10,input$slider)[i],";",seq(0,10,input$slider)[i+1],"]")},a(),
                                                    paste0("]", max(seq(0,10,input$slider)),";","Inf","["),
                                                    nrow(myReactives$credit[which(myReactives$credit$Defaut>=seq(0,10,input$slider)[1] & myReactives$credit$Defaut<=seq(0,10,input$slider)[2]),]),
                                                    for (i in 2:(length(seq(0,10,input$slider))-2)){
                                                      b()[i-1] <- nrow(myReactives$credit[which(myReactives$credit$Defaut>seq(0,10,input$slider)[i] & myReactives$credit$Defaut<=seq(0,10,input$slider)[i+1]),])},
                                                    b(),
                                                    nrow(myReactives$credit[which(myReactives$credit$Defaut>max(seq(0,10,input$slider))),])),nrow = (length(seq(0,10,input$slider))-1), ncol = 2))})
      output$my_table  <- renderDataTable({
        df()
      })
    }))
runApp(
名单(
ui=仪表板页面(
仪表板标题(title=“Crédit”),
仪表板侧栏(
侧边栏菜单(
menuItem(“视觉化”,tabName=“视觉化”,icon=icon(“投票”))
)),
仪表板主体(
tabItems(
#形象化
tabItem(tabName=“可视化”,
h1(“视觉化设计”),
h2(“画面勘探”),
dataTableOutput('dataTable'),
h2(“图形”),
fluidRow(
列(5,绘图输出(“绘图1”),
列(4,日期范围输入(“日期”,标签=h3(“日期范围”),
开始=截止日期(“1972-09-30”))
),
第(4)栏,
sliderInput(“滑块”,标签=h3(“滑块”),最小值=0,
最大值=5,值=1,步长=0.5),
第(6)栏,
dataTableOutput('my_table')
)))
)
)))
,服务器=功能(输入,输出){

myReactives您不能为反应函数的结果赋值:

# Correct:
a <- reactive({as.data.frame(matrix(data = NA, nrow = (length(seq(0,10,input$slider))-1), ncol = 1))})

# Wrong:
a()[i-1] <- paste0(...)

#正确:

a如果我听说“可编辑的data.frame for Shining”看了之后,我想到了
rhandsontable
,我不认为这是我要找的。我只想在设计数据帧时考虑SliderInput的输出,以便使用它创建一个数据帧。但是感谢您提供此功能。感谢您的回答,我考虑了您的解决方案。不过,我有这个印象这是正确的,你只能在其他反应式表达式中使用反应式函数,我澄清了我的编辑很棒,谢谢!现在我的矩阵的内容也有问题。向量只取第一个值并复制它。错误如下:
W在中,我感觉它是在for循环中,在退出时。在错误中,我们可以很容易地看到它找到了我想要的术语,但是它不把它放在向量中,因为它是错误的。好的,请考虑接受我的部分答案,这样别人也可以从中受益。
# Correct:
a <- reactive({as.data.frame(matrix(data = NA, nrow = (length(seq(0,10,input$slider))-1), ncol = 1))})

# Wrong:
a()[i-1] <- paste0(...)

reactive({
  a_ <- a()
  a_[i-1] <- paste0(...)
  ...
})