In running the below example R Shiny code, the "parentTbl" table is presented at the top of the window, and second table "childTbl" should be rendered by the user checking the checkboxInput()
. However, for some reason the "childTbl" is only rendered (after checking the checkboxInput()
) if the user actually clicks on any cell in the "parentTbl", whether or not a value is entered. Why is this, and how can this be fixed? The "childTbl" should render without the user having to first interact with "parentTbl".
One fix is to wrap the output$childTbl
section of code with a conditional such as if(input$showCurves){rhandsontable(iris[1:5,1:5])}
, but I'd rather not do this and I wonder if there is a more direct fix. Incorporating this particular conditional into the larger code this example derives from causes other problems. I'd like to try out other solutions.
Code:
library(shiny)
library(rhandsontable)
ui <- fluidPage(
rHandsontableOutput("parentTbl"),
checkboxInput("showCurves", "Add curves", FALSE),
conditionalPanel(
condition = "input.showCurves == true",
rHandsontableOutput("childTbl"))
)
server <- function(input, output, session) {
output$parentTbl <- renderRHandsontable({
rhandsontable(mtcars[1:5,1:5])
})
output$childTbl <- renderRHandsontable({
if(input$showCurves){rhandsontable(iris[1:5,1:5])}
})
}
shinyApp(ui, server)
A trusty observeEvent()
appears to resolve this:
observeEvent(input$showCurves, {
output$childTbl <- renderRHandsontable({
rhandsontable(iris[1:5, 1:5])
})
}, ignoreInit = TRUE)