Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.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 Shining handsontable重置为默认值_R_Shiny_Shiny Reactivity_Rhandsontable - Fatal编程技术网

防止R Shining handsontable重置为默认值

防止R Shining handsontable重置为默认值,r,shiny,shiny-reactivity,rhandsontable,R,Shiny,Shiny Reactivity,Rhandsontable,我已经创建了以下闪亮的应用程序 library(shiny) library(rhandsontable) ui <- fluidPage( sidebarLayout(sidebarPanel = "Inputparameter", selectInput(inputId = "Name", label = "Name", choices = c("A", "B&qu

我已经创建了以下闪亮的应用程序

library(shiny)
library(rhandsontable)

ui <- fluidPage(  
sidebarLayout(sidebarPanel = "Inputparameter", 
            selectInput(inputId = "Name", label = "Name", choices = c("A", "B", "C"))),                
            mainPanel (rHandsontableOutput(outputId = 'Adjusttable', width ='100%', height = 100%')))

server <- function(input, output, session) {  
output$Adjusttable<-renderRHandsontable({
DF = data.frame(ID = 1:7,'Column2' = 0, Start = "D",FM="",stringsAsFactors = FALSE)
names(DF)[names(DF)=='Column2']<- input$Name
names(DF)[names(DF)=='FM']<-'FM'
DF$ID<-NULL
rhandsontable(DF, width = 280, height = 677,stretchH = "all")  %>%
  hot_col(col = "Start", type = "dropdown", source = c("Fw", "Sw"), fillHandle = 
  list(direction='vertical', autoInsertRow=TRUE))%>%
  hot_context_menu(allowRowEdit = TRUE, allowColEdit = FALSE)
  }, quoted = FALSE )}

 shinyApp(ui, server)
库(闪亮)
图书馆(rhandsontable)
ui试试这个

library(shiny)
library(rhandsontable)
library(DT)

DF <- data.frame(ID = 1:7,Column2 = 0, Start = "D",FM="",stringsAsFactors = FALSE)
names(DF)[names(DF)=='FM']<-'FM'
DF$ID<-NULL

ui <- fluidPage(  
  sidebarLayout(
    sidebarPanel( "Inputparameter", 
                selectInput(inputId = "Name", label = "Name", choices = c("A", "B", "C"))),                
    mainPanel( rHandsontableOutput(outputId = 'hot', width ='100%', height = '100%') 
               , DTOutput("t1")
               ) 
    )
)

server <- function(input, output, session) {

  DF1 <- reactiveValues(data=DF)
  observe({
    input$Name
    names(DF1$data)[1] <- input$Name
  })
  
  output$hot<-renderRHandsontable({
    
    rhandsontable(DF1$data, width = 280, height = 677,stretchH = "all")  %>%
      hot_col(col = "Start", type = "dropdown", source = c("Fw", "Sw"), fillHandle = 
                list(direction='vertical', autoInsertRow=TRUE)) %>%
      
      hot_context_menu(allowRowEdit = TRUE, allowColEdit = FALSE)
  }, quoted = FALSE )
  
  observe({
    if (!is.null(input$hot)){
      DF1$data <- (hot_to_r(input$hot))
    } 
  })
  
  output$t1 <- renderDT(DF1$data)

}

shinyApp(ui, server)
库(闪亮)
图书馆(rhandsontable)
图书馆(DT)

谢谢。将数据帧创建步骤移出handson表循环是一个重要步骤。应该可以动态地改变侧栏中的列数