我面临着与rhandsontables相关的各种操作的挑战,尽管它们对于我正在尝试创建的应用程序来说似乎是无价的。我的第一个挑战是,我试图通过过滤来自用户输入的原始数据帧来更新rhandsontable,这是从下拉列表(selectInput)中选择的。
下面是一个简化的可重现的例子,它得到了我想要的结果,但不是通过我想要的方式:
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?
发布于 2021-01-28 05:19:02
您可能希望在ui中为您的choices使用counties的levels。
此外,在server中,您可以使用reactive表达式来过滤数据。如果您希望对selectInput中的更改做出反应(我假设您的意思是,而不是sliderInput),那么它应该是一个反应式表达式。
引用时,需要包括括号。例如,如果您将反应式表达式称为datavalues,那么datavalues()应该用于rhandsontable中的数据。
如果这是你要找的东西,请告诉我。
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)
})
}https://stackoverflow.com/questions/65925216
复制相似问题