作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我有以下 Shiny 的应用程序:
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)
最佳答案
可以将整个表和单个列设置为只读以防止用户进行更改。( 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)
关于r - 在 rhandsontable 中禁用列编辑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37436556/
我是一名优秀的程序员,十分优秀!