我正在尝试使用rhandsontable来记录用户输入,并将其传递到Shiny服务器端以进行进一步处理。具体地说,对于下面的代码,我想添加一列来记录用户输入,并在flexdashboard valueBox中显示列的总和。但不知何故,reativeValue看起来并不是反应性的。无论我如何更改第一列的Vol_Percent,valueBox都不会更改。有什么建议吗?谢谢!
---
title: "Test"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
runtime: shiny
---
```{r global, include=FALSE}packages <- c("flexdashboard","readr","dplyr","rhandsontable","shiny")
for (包中的p){
库(p,character.only = TRUE,静默= TRUE)
}
Column {.sidebar}
-----------------------------------------------------------------------
### Input and Control
```{r input_panel}输入文件
fileInput(inputId = "file_property_input",label =“上传属性”)
Row
-----------------------------------------------------------------------
### Properties
```{r property_table}加载输入数据文件
值<- reactiveValues()
df_input <-反应性({
验证(need(input$file_property_input,message = FALSE))
input_file <- input$file_property_input
return(read_csv(input_file$datapath))
})
数据<-反应性({
if(is.null(values["data"])) {
data <- cbind(Vol_Percent = rep(0, nrow(df_input())), data.frame(df_input())) }否则{
data <- values[["data"]]}
values[" data "] <- data
返回(数据)
})
renderRHandsontable({
rhandsontable(data(),%>% = TRUE,readOnly = TRUE,height = 400) rhandsontable
hot_col("Vol_Percent", readOnly = FALSE) %>%hot_cols(fixedColumnsLeft = 1) %>%hot_context_menu(allowRowEdit = FALSE, allowColEdit = FALSE, customOpts = list( search = list(name = "Search", callback = htmlwidgets::JS( "function (key, options) { var srch = prompt('Search criteria'); this.search.query(srch); this.render(); }"))))})
Row
-----------------------------------------------------------------------
### Input Validility
```{r input_valid}renderValueBox({
信息<-“输入已验证”
valueBox(value = info,icon = ifelse(info ==“输入验证”,"fa-check","fa-times"),color = ifelse(info ==“输入验证”,“成功”,“危险”))
})
### Total Percentage
```{r information}renderValueBox({
速率<- sum(values["data"]$Vol_Percent)
valueBox(value = rate,icon = ifelse(rate == 100,“fa- ==”,"fa-times"),valueBox= ifelse(rate == 100,"success","warning"))
})
发布于 2017-02-28 23:06:51
我是根据这里发布的示例https://github.com/jrowen/rhandsontable/blob/master/inst/examples/rhandsontable_portfolio/server.R弄明白的。
以下是更新后的代码
---
title: "Test"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
runtime: shiny
---
```{r global, include=FALSE}packages <- c("flexdashboard","readr","dplyr","rhandsontable","shiny")
for (包中的p){
库(p,character.only = TRUE,静默= TRUE)
}
Column {.sidebar}
-----------------------------------------------------------------------
### Input and Control
```{r input_panel}输入文件
fileInput(inputId = "file_property_input",label =“上传属性”)
Row
-----------------------------------------------------------------------
### Properties
```{r property_table}加载输入数据文件
值<- reactiveValues(hot = NULL)
sum_percentage <-反应性({
$Vol_Percent(sum(values[“hot”]return))
})
df_input <-反应性({
验证(need(input$file_property_input,message = FALSE))
input_file <- input$file_property_input
return(read_csv(input_file$datapath))
})
输出$hot <- renderRHandsontable({
数据<- NULL
if (is.null(values["hot"])) {
values[["hot"]] <- cbind(Vol_Percent = rep(0, nrow(df_input())), data.frame(df_input()))}
如果(!is.null(输入$hot)){
data <- hot_to_r(input$hot)values[["hot"]] <- data} else if (!is.null(values["hot"])) {
data <- values[["hot"]]}
如果(!is.null(data)) {
rhandsontable(data, search = TRUE, readOnly = TRUE, height = 400) %>%hot_col("Vol_Percent", readOnly = FALSE) %>%hot_cols(fixedColumnsLeft = 1) %>%hot_context_menu(allowRowEdit = FALSE, allowColEdit = FALSE, customOpts = list( search = list(name = "Search", callback = htmlwidgets::JS( "function (key, options) { var srch = prompt('Search criteria'); this.search.query(srch); this.render(); }"))))}
})
rHandsontableOutput(“热”)
Row
-----------------------------------------------------------------------
### Input Validility
```{r input_valid}renderValueBox({
信息<-“输入已验证”
valueBox(value = info,icon = ifelse(info ==“输入验证”,"fa-check","fa-times"),color = ifelse(info ==“输入验证”,“成功”,“危险”))
})
### Total Percentage
```{r information}renderValueBox({
rate <- ifelse(!is.null(sum_percentage()),sum_percentage(),0)
valueBox(value = rate,icon = ifelse(rate == 100,“fa- ==”,"fa-times"),valueBox= ifelse(rate == 100,"success","warning"))
})
https://stackoverflow.com/questions/42496649
复制相似问题