首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从sliderInput更新rhandsontable

从sliderInput更新rhandsontable
EN

Stack Overflow用户
提问于 2021-01-28 02:29:50
回答 1查看 27关注 0票数 0

我面临着与rhandsontables相关的各种操作的挑战,尽管它们对于我正在尝试创建的应用程序来说似乎是无价的。我的第一个挑战是,我试图通过过滤来自用户输入的原始数据帧来更新rhandsontable,这是从下拉列表(selectInput)中选择的。

下面是一个简化的可重现的例子,它得到了我想要的结果,但不是通过我想要的方式:

代码语言:javascript
复制
library(shiny)
library(rhandsontable)
library(tidyverse)

counties = as.factor(c(rep("County1", 2), rep("County2", 2)))
compnames = as.factor(c("comp1", "comp2", "comp3", "comp4"))
properties = 1:4
soilsData <- data.frame(county = counties, compname = compnames, property = properties)

ui <- fluidPage(
    
    selectInput(inputId = "selectCounty", label = h4("Select County"), 
                choices = counties,
                selected = "County1",
                multiple = FALSE),
    br(),
    br(),
    rHandsontableOutput('rTable'),
    
)

server <- function(input, output) {
 
    df1 <- df %>% 
        filter(county == "County1", compname == "comp1")
    
    datavalues <- reactiveValues(data = df1)

    output$rTable <- renderRHandsontable ({
        rhandsontable(datavalues$data,
                      rowHeaders = NULL)
    })
}

如何通过所选sliderInput创建df1?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-28 05:19:02

您可能希望在ui中为您的choices使用countieslevels

此外,在server中,您可以使用reactive表达式来过滤数据。如果您希望对selectInput中的更改做出反应(我假设您的意思是,而不是sliderInput),那么它应该是一个反应式表达式。

引用时,需要包括括号。例如,如果您将反应式表达式称为datavalues,那么datavalues()应该用于rhandsontable中的数据。

如果这是你要找的东西,请告诉我。

代码语言:javascript
复制
library(shiny)
library(rhandsontable)
library(tidyverse)

ui <- fluidPage(
  selectInput(inputId = "selectCounty", 
              label = h4("Select County"), 
              choices = levels(counties),
              selected = "County1",
              multiple = FALSE),
  br(),
  br(),
  rHandsontableOutput('rTable'),
)

server <- function(input, output) {
  
  datavalues <- reactive({
    soilsData %>% 
      filter(county == input$selectCounty, 
             compname == "comp1")
  })
  
  output$rTable <- renderRHandsontable ({
    rhandsontable(datavalues(),
                  rowHeaders = NULL)
  })
  
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65925216

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档