2016-05-25 2 views
1

私は、次の光沢のあるアプリがあるとします。rhandsontableで列編集を無効にしますか?

library(shiny) 
library(rhandsontable) 

ui <- shinyUI(fluidPage(
    titlePanel("Handsontable"), 
    sidebarLayout(
    sidebarPanel(
     helpText("Handsontable demo output. Column add/delete does work ", 
       "for tables with defined column properties, including type."), 
     radioButtons("useType", "Use Data Types", c("TRUE", "FALSE")) 
    ), 
    mainPanel(
     rHandsontableOutput("hot", width = 350) 
    ) 
) 
)) 

server <- shinyServer(function(input, output, session) { 
    values = reactiveValues() 

    data = reactive({ 
    if (!is.null(input$hot)) { 
     DF = hot_to_r(input$hot) 
    } else { 
     if (is.null(values[["DF"]])) 
     DF = data.frame(val = 1:10, bool = TRUE, nm = LETTERS[1:10], 
         dt = seq(from = Sys.Date(), by = "days", length.out = 10), 
         stringsAsFactors = F) 
     else 
     DF = values[["DF"]] 
    } 


    values[["DF"]] = DF 
    DF 
    }) 

    output$hot <- renderRHandsontable({ 
    DF = data() 
    if (!is.null(DF)) 
     rhandsontable(DF, useTypes = as.logical(input$useType), stretchH = "all") 
    }) 
}) 

# Run the application 
shinyApp(ui = ui, server = server) 

は、どのように私は最初の2つの列のために編集を無効にすることができますか?

答えて

1

テーブル全体および個々の列は、変更を行うからユーザーを防止するために、読み取り専用に設定することができる。(http://jrowen.github.io/rhandsontable/#read-only

library(shiny) 
library(rhandsontable) 

ui <- shinyUI(fluidPage(
    titlePanel("Handsontable"), 
    sidebarLayout(
    sidebarPanel(
     helpText("Handsontable demo output. Column add/delete does work ", 
       "for tables with defined column properties, including type."), 
     radioButtons("useType", "Use Data Types", c("TRUE", "FALSE")) 
    ), 
    mainPanel(
     rHandsontableOutput("hot", width = 350) 
    ) 
) 
)) 

server <- shinyServer(function(input, output, session) { 
    values = reactiveValues() 

    data = reactive({ 
    if (!is.null(input$hot)) { 
     DF = hot_to_r(input$hot) 
    } else { 
     if (is.null(values[["DF"]])) 
     DF = data.frame(val = 1:10, bool = TRUE, nm = LETTERS[1:10], 
         dt = seq(from = Sys.Date(), by = "days", length.out = 10), 
         stringsAsFactors = F) 
     else 
     DF = values[["DF"]] 
    } 


    values[["DF"]] = DF 
    DF 
    }) 

    output$hot <- renderRHandsontable({ 
    DF = data() 
    if (!is.null(DF)) 
     rhandsontable(DF, useTypes = as.logical(input$useType), stretchH = "all") %>% 
     hot_col("val", readOnly = TRUE) %>% 
     hot_col("bool",readOnly = TRUE) 
    }) 
}) 

# Run the application 
shinyApp(ui = ui, server = server) 
関連する問題