Hi,
After testing adding outputOptions calls in my bigger application, I have a follow-up question with respect to the use of outputOptions call with rhandsontable output. In the updated code below, although the reactivity seems correct based upon the content of the text box, the display of the table itself is weird. Removing the outputOptions call relative to the table object solves the display problem but breaks the full reactivity.
Any idea?
require(shiny)
require(shinydashboard)
require(rhandsontable)
make.txt <- function(input, table){
c(
sprintf('Choice: %s', input$choiceInput),
sprintf('Sub-choice: %s', input$subchoiceInput),
sprintf('Table content: %s', paste(table[,1], collapse = ', '))
)
}
myServer <- function(input, output, session) {
output$table <- renderRHandsontable({
if (input$choiceInput=='A'){
DF <- data.frame(animal = c('alligator', 'albatros'),
color = c('green', 'white'))
} else {
DF <- data.frame(animal = c('bear', 'bee'),
color = c('black', 'yellow'))
}
rhandsontable(
data = DF,
rowHeaders = NULL,
contextMenu = FALSE,
width = 600,
height = 300
)
})
outputOptions(output, 'table', suspendWhenHidden = FALSE)
#subchoiceUI
output$subchoiceUI <- renderUI({
if (input$choiceInput == 'A'){
subchoices <- paste0('a', 1:5)
} else {
subchoices <- paste0('b', 11:15)
}
fluidRow(
column(
width =12,
selectInput(
inputId = 'subchoiceInput',
label = 'Sub choice',
choices = subchoices,
selected = subchoices[1],
width = '100%'
),
hr(),
rHandsontableOutput('table')
)
)
})
outputOptions(output, 'subchoiceUI', suspendWhenHidden = FALSE)
# text UI
mytext <- reactive({
return(make.txt(input, hot_to_r(input$table)))
})
output$textUI <- renderText({
paste(mytext(), collapse = '\n')
})
}
myUI <- function(){
fluidPage(
fluidRow(
column(
width = 6,
tabBox(
tabPanel(
title = 'Settings',
fluidRow(
column(
width = 12,
selectInput(
inputId = 'choiceInput',
label = 'Choice',
choices = c('A','B'),
selected = 'A',
width = '100%'
)
)
)
),
tabPanel(
title = 'Sub-settings',
fluidRow(
column(
width = 12,
uiOutput('subchoiceUI')
)
)
),
width = 12
)
),
column(
width = 6,
box(
width = 12,
title = 'Text box',
verbatimTextOutput('textUI')
)
)
)
)
}
shinyApp(ui = myUI, server = myServer)