Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取R中反应数据框的行名,并创建日期范围滑块_R_Shiny_Reactive - Fatal编程技术网

获取R中反应数据框的行名,并创建日期范围滑块

获取R中反应数据框的行名,并创建日期范围滑块,r,shiny,reactive,R,Shiny,Reactive,我有一个以时间序列为索引的数据帧。数据框中的数据通过仪表板操作(例如下载按钮)进行更新,因此数据框是被动的。使用滑块,我希望能够仅选择数据帧的某些行。因此,滑块的最小-最大值指的是反应数据帧的行名。到目前为止,我无法实现这一点。下面是代码。服务器部分中的if0部分就是我所说的部分。谢谢你的帮助 require(shiny) AquireData <- function(){ # In this function the data are created df <- data

我有一个以时间序列为索引的数据帧。数据框中的数据通过仪表板操作(例如下载按钮)进行更新,因此数据框是被动的。使用滑块,我希望能够仅选择数据帧的某些行。因此,滑块的最小-最大值指的是反应数据帧的行名。到目前为止,我无法实现这一点。下面是代码。服务器部分中的if0部分就是我所说的部分。谢谢你的帮助

require(shiny)

AquireData <- function(){
  # In this function the data are created
  df <- data.frame(replicate(3,sample(0:50,1000,rep=TRUE)))
  rownames(df)  <- seq(from = as.POSIXct("2012-05-15 07:00"), 
                       to = as.POSIXct("2019-05-17 18:00"), by = "min")[0:dim(df)[1]]
  names(df) <- c('A','B','C')
  return (df)
}


ui <- fluidPage(
  # App title
  titlePanel("my dashboard"),

  # define stuff for the sidebar (buttons, selectlists etc.). These items will
  # be displayed for all panels
  sidebarLayout(
    sidebarPanel(
      actionButton("Button_GetAndUpdate", "Update data"),
      sliderInput("start_end_dates", "Date range", min =0, max=0, value=1)
    ),

    # Main panel. Here you can display your graphs, plots and tables
    mainPanel("observed data", tableOutput("rawdata"))      

  )
)


server <- function(input, output,session) {
  # When the app is called an update of the data is drawn
  df_data <- reactive({AquireData()})

  # Check what the update button is doing. If its getting pressed pull and update
  observeEvent (input$Button_GetAndUpdate,{df_data <<- reactive({AquireData()})})  


  # set date range slider values using the dates from the data frame index
  if(0){
    updateSliderInput(session, "start_end_dates",
                      label = "Date range",
                      min = as.POSIXct(min(rownames(df_data())),"%Y-%m-%d %H:%M:%S",tz=""),
                      max = as.POSIXct(max(rownames(df_data())),"%Y-%m-%d %H:%M:%S",tz="")
    )
  }
  # get the head of the dataframe
  data_head <- reactive({
    input$Button_GetAndUpdate
    isolate({
      head(df_data())
    })
  })

  output$rawdata <- renderTable({
    data_head()
  })   
}

shinyApp(ui = ui, server = server)
runApp("Header_dashboard")
您可以分别使用shinyWidgets::SliderOutput和shinyWidgets::updateSliderTextInput而不是SliderInput来执行以下操作:

shinyWidgets::updateSliderTextInput 会话,开始日期和结束日期, 选项=行名称DF_数据 这意味着您的应用程序:

要求透明
获取数据您可能想查看dateRangeInput和shinyTime::timeInput