在应用程序中编辑rhandsontable后更新selectInput()选项
我有一个简单的闪亮应用程序,其中我使用在应用程序中编辑rhandsontable后更新selectInput()选项,r,shiny,R,Shiny,我有一个简单的闪亮应用程序,其中我使用numericInput()“tests”向数据框添加行。然后我将“Label”列的名称作为选项提供给selectInput()“Label2”。问题是,当我编辑表“Label”列中的名称时,selectInput()选项不会相应地更新。例如,如果我将表中的“Test 1”重命名为“Test A”,我希望它也在selectInput()中更改 #ui.r 图书馆(闪亮) 图书馆(rhandsontable) ui这似乎有效。您没有读回已编辑的rhandson
numericInput()
“tests”向数据框添加行。然后我将“Label”列的名称作为选项提供给selectInput()
“Label2”。问题是,当我编辑表“Label”列中的名称时,selectInput()
选项不会相应地更新。例如,如果我将表中的“Test 1”重命名为“Test A”,我希望它也在selectInput()中更改
#ui.r
图书馆(闪亮)
图书馆(rhandsontable)
ui这似乎有效。您没有读回已编辑的rhandsontable
在你的代码中。
因此,我添加了一个observe
来执行此操作
observe({
if(!is.null(input$hot3))
rt4$DF <- hot_to_r(input$hot3)
})
查找updateselectinput以了解此问题。当我使用updateselectinput()时,我使用“运算符对原子向量无效”,这是一个例外答案。感谢您的有用修复!问题:“req(input$text2)”在RenderHandsOnTable中做什么?它处理空值和空格。本质上,只有当req中的条件为非空白时,req下的其余代码才会执行。它与rhandsontable本身没有任何关系
observe({
if(!is.null(input$hot3))
rt4$DF <- hot_to_r(input$hot3)
})
#ui.r
library(shiny)
library(rhandsontable)
ui <- navbarPage(
"Application",
tabPanel("General",
sidebarLayout(
sidebarPanel(
uiOutput("tex2")
),
mainPanel(
rHandsontableOutput("hot3"),
uiOutput("book12")
)
)))
#server.r
server <- function(input, output,session) {
rt4<- reactiveValues()
output$tex2<-renderUI({
numericInput("text2", "#tests", value = 1, min=1)
})
output$book12<-renderUI({
selectInput("bk12",
"Label2",
choices=(rt4$DF$Label))
})
observe({
req(input$text2)
rt4$DF <- data.frame(
Test=paste(1:input$text2),
Label=paste("Test",1:isolate(input$text2)),
stringsAsFactors = FALSE)
})
output$hot3 <-renderRHandsontable({
req(input$text2)
rhandsontable(rt4$DF)
} )
observe({
if(!is.null(input$hot3))
rt4$DF <- hot_to_r(input$hot3)
})
}
shinyApp(ui,server)