本质上,我试图在 Rhandsontables 之间切换,这些 Rhandsontables 也具有操作它们的外部小部件。此外,这些表中还有基础公式。这些表本质上是相同的,小部件和公式在两种情况下的工作方式相同,我希望能够在它们之间切换。下面的例子可能是为了提供信息......
library(shiny)
library(rhandsontable)
RepData1 <- data.frame(col1 = c(1:10)
,col2 = "C1"
,col3 = runif(10,0,0.023)
,col4 = runif(10,0,1))
RepData2 <- data.frame(col1 = c(1:10)
,col2 = "C2"
,col3 = runif(10,0,0.023)
,col4 = runif(10,0,1))
ui=fluidPage(
sliderInput("mySlider",label="Slider", min = 0, max = 100, post = " %", value = 50)
,numericInput("Total", "Total:", 500000)
,verbatimTextOutput("value")
,fluidRow(
column(3, radioButtons("Buttn10", label="col", choices= c("C1","C2"), selected = "C1", inline = TRUE))
,column(6,rHandsontableOutput("hotable1"))
)
)
server <- shinyServer(function(input, output, session) {
selData <- ""
previous <- reactive({
if(input$Buttn10 == "C1") {
if(selData == "" | selData == "C2") {
selData <<- "C1"
return(RepData1)
}
} else {
if(selData == "C1") {
selData <<- "C2"
return(RepData2)
}
}
})
MyChanges <- reactive({
if(is.null(input$hotable1)){
return(previous())
} else if(!identical(previous(),input$hotable1)){
mytable <- as.data.frame(hot_to_r(input$hotable1))
x <- input$Total*(input$mySlider/100)
mytable$QTY <- x*mytable$col4
mytable
}
})
output$hotable1 <- renderRHandsontable({
if(is.null(MyChanges())) return()
df_ <- MyChanges()
rhandsontable(df_, readOnly = FALSE, rowHeaders= NULL, useTypes= TRUE) %>%
hot_table(highlightCol = TRUE, highlightRow = TRUE)
})
})
shinyApp(ui,server)
在这种情况下,小部件和公式工作,但不是切换......