Hi would like to have a dynamic(changing number of rows) rhandsontable using the input from radio buttons.
So I've been working on a shiny that needs data input into a table. However when adding more complexity an annual option was needed. So with the current table I could ask the user to fill in only the first row but that is just not pretty.
This is a reproducible example of the table as it currently stands
library(shiny)
library(rhandsontable)
ui <- fluidPage(
br(),
rHandsontableOutput('table'),
textOutput('result'),
br(),
actionButton("recalc", "re-enter data")
)
rowNames <- c("Spring", "Summer", "Autum", "Winter", "Sum")
defaultDF <- data.frame(
row.names = rowNames,
Lake = rep(NA_integer_, 5),
Beach = rep(NA_integer_, 5),
Garden = rep(NA_integer_, 5),
stringsAsFactors = FALSE
)
server <- function(input, output, session)
({
values <- reactiveValues(data = defaultDF) ## assign it with NULL
## button press resets now the data frame
observeEvent(input$recalc, {
values$data[] <- NA_integer_
})
observe({
req(input$table)
DF <- hot_to_r(input$table)
DF[setdiff(rowNames, "Sum"),]
DF["Sum",] <- colSums(DF[setdiff(rowNames, "Sum"),], na.rm = TRUE)
values$data <- DF
})
output$table <- renderRHandsontable({
req(values$data)
rhandsontable(values$data, rowHeaderWidth = 100) %>%
hot_row(nrow(values$data), readOnly = TRUE)
})
})
shinyApp(ui = ui, server = server)
What I'm attempting to do (in the code below) is to use the value in the radio buttons to change the number of rows in the table. Unfortunatly it has not worked. Any pointer would be very much appreciated.
library(shiny)
library(rhandsontable)
ui <- fluidPage(
br(),
rHandsontableOutput('table'),
textOutput('result'),
br(),
actionButton("recalc", "re-enter data")
radioButtons("Step", label = h4("Choose Step"),
choices = list("Annual" = 2, "Season" = 5),
inline= TRUE, selected = 1),
)
server <- function(input, output) ({
tabval<- reactive({
SeasonAnunal<- rowNames <- if (input$Step==2){ rowNames <- c("Spring", "Summer", "Autum", "Winter", "Sum")
} else{
rowNames <-c("Annual","Sum")}
defaultDF <- data.frame(
row.names = rowNames,
Lake = rep(NA_integer_, tabval()),
Beach = rep(NA_integer_, tabval()),
Garden = rep(NA_integer_, tabval()),
stringsAsFactors = FALSE)
})
values <- reactiveValues(data = defaultDF) ## assign it with NULL
## button press resets now the data frame
observeEvent(input$recalc, {
values$data[] <- NA_integer_
})
observe({
req(input$table)
DF <- hot_to_r(input$table)
DF[setdiff(rowNames, "Sum"),]
DF["Sum",] <- colSums(DF[setdiff(rowNames, "Sum"),], na.rm = TRUE)
values$data <- DF
})
output$table <- renderRHandsontable({
req(values$data)
rhandsontable(values$data, rowHeaderWidth = 100) %>%
hot_row(nrow(values$data), readOnly = TRUE)
})
})
shinyApp(ui = ui, server = server)
I'm not sure how your annual table should look like, but please check the following:
library(shiny)
library(rhandsontable)
ui <- fluidPage(
br(),
rHandsontableOutput('table'),
textOutput('result'),
br(),
actionButton("recalc", "re-enter data"),
radioButtons("Step", label = h4("Choose Step"),
choices = list("Annual" = 2, "Season" = 5),
inline= TRUE, selected = 2)
)
rowNames <- list("5" = c("Spring", "Summer", "Autum", "Winter", "Sum"), "2" = c("Year", "Sum"))
server <- function(input, output, session)
({
values <- reactiveValues(data = NULL) ## assign it with NULL
observeEvent(input$Step, {
req(input$Step)
values$data <- data.frame(
row.names = rowNames[[input$Step]],
Lake = rep(NA_integer_, as.integer(input$Step)),
Beach = rep(NA_integer_, as.integer(input$Step)),
Garden = rep(NA_integer_, as.integer(input$Step)),
stringsAsFactors = FALSE
)
})
## button press resets now the data frame
observeEvent(input$recalc, {
values$data[] <- NA_integer_
})
observe({
req(input$table)
DF <- hot_to_r(input$table)
DF[setdiff(rownames(DF), "Sum"),]
DF["Sum",] <- colSums(DF[setdiff(rownames(DF), "Sum"),], na.rm = TRUE)
values$data <- DF
})
output$table <- renderRHandsontable({
req(values$data)
rhandsontable(values$data, rowHeaderWidth = 100) %>%
hot_row(nrow(values$data), readOnly = TRUE)
})
})
shinyApp(ui = ui, server = server)
Related
I am working on this code where I am trying to make a new row and my existing rows has this actionbutton "Reward", after I try to insert a new row the actionbutton does not show up on the new row, is there a way I can add the actionbutton to the new row?
Also after adding a new row "1" shows up where Names would be, is there a way to get rid of that 1?
Thank you in advance! Any help is greatly appreciated.
library(shiny)
library(DT)
library(tidyverse)
dFramex <- data.frame(Name = c('Dilbert', 'Alice', 'Wally', 'Ashok', 'Dogbert'),
Motivation = c(62, 73, 3, 99, 52))
ui <- fluidPage(
fluidRow(
actionButton("save","Add Data"),
DT::dataTableOutput(outputId = "table")
)
)
server <- function(input, output, session) {
shinyInput <- function(FUN, len, id, ...) {
inputs <- character(len)
for (i in seq_len(len)) {
inputs[i] <- as.character(FUN(paste0(id, i), ...))
}
inputs
}
user_table <-
dFramex %>%
slice(1) %>%
replace(values = "")
df <- reactiveValues(data = data.frame(
dFramex,
Actions = shinyInput(actionButton, nrow(dFramex),
'button_', label = "Reward", onclick = 'Shiny.onInputChange(\"select_button\", this.id)' ),
stringsAsFactors = FALSE
))
output$table <-
DT::renderDataTable({DT::datatable({ df$data
},options = list(searching = FALSE, selection= FALSE)
,editable = TRUE,
escape = FALSE,
rownames = FALSE
)
}, server = FALSE)
proxy <- dataTableProxy(outputId = "table")
observeEvent(eventExpr = input$save, {
proxy %>%
addRow(user_table)
})
}
shinyApp(ui, server)
Try this
library(shiny)
library(DT)
library(tidyverse)
dFramex <- data.frame(Name = c('Dilbert', 'Alice', 'Wally', 'Ashok', 'Dogbert'),
Motivation = c(62, 73, 3, 99, 52))
ui <- fluidPage(
fluidRow(
actionButton("save","Add Data"),
DT::dataTableOutput(outputId = "table")
)
)
server <- function(input, output, session) {
shinyInput <- function(FUN, len, id, m, ...) {
if (m==1){
inputs <- character(len)
for (i in seq_len(len)) {
inputs[i] <- as.character(FUN(paste0(id, i), ...))
}
}else {
inputs <- character(1)
inputs <- as.character(FUN(paste0(id, m), ...))
}
inputs
}
df <- reactiveValues(data = data.frame(
dFramex,
Actions = shinyInput(actionButton, nrow(dFramex),
'button_', 1, label = "Reward", onclick = 'Shiny.onInputChange(\"select_button\", this.id)' ),
stringsAsFactors = FALSE
))
output$table <-
DT::renderDataTable({DT::datatable({ df$data
},options = list(searching = FALSE, selection= FALSE)
,editable = TRUE,
escape = FALSE,
rownames = FALSE
) }, server = FALSE)
proxy <- dataTableProxy(outputId = "table")
observeEvent(eventExpr = input$save, {
m <- nrow(dFramex) + as.numeric(input$save)
user_table <- dFramex %>% slice(1) %>%
dplyr::mutate(Actions = shinyInput(actionButton, 1,
'button_', m, label = "Reward", onclick = 'Shiny.onInputChange(\"select_button\", this.id)' ))
proxy %>% addRow(user_table)
})
}
shinyApp(ui, server)
I have a fully functioning shiny app for performing regression analysis, with summary(), tidy(), and augment().
However, I would like to add a filter selection in the shiny for the uploaded data.
My dataset is quite big and within the dataset, it is divided into 5 types, (so, type_1, type_2, type_3, etc). Right now I have to divide my dataset manually outside the shiny app to 5 different datasets so I can only run the regression for one specific type at a time.
It would be great to be able to choose and select the type within the shiny, without going through all this hassle.
Grateful for all your help.
library(shiny)
library(shinyWidgets)
library(DT)
library(dplyr)
library(nlme)
library(broom)
ui <- navbarPage("dd",
tabPanel("Reg",
sidebarPanel(
fileInput(
inputId = "filedata",
label = "Upload data. csv",
multiple = FALSE,
accept = c(".csv"),
buttonLabel = "Choosing ...",
placeholder = "No files selected yet"
),
uiOutput("xvariable"),
uiOutput("yvariable")
),
mainPanel(
DTOutput("tb1"),
fluidRow(
column(6, verbatimTextOutput('lmSummary')),
column(6,verbatimTextOutput("tid")),
column(6,verbatimTextOutput("aug"))
)
)
)
)
server <- function(input, output, session) {
data_1 <- reactive({
req(input$filedata)
inData <- input$filedata
if (is.null(inData)){ return(NULL) }
mydata <- read.csv(inData$datapath, header = TRUE, sep=",")
})
output$tb1 <- renderDT(head(data_1()))
output$xvariable <- renderUI({
req(data_1())
xa<-colnames(data_1())
pickerInput(inputId = 'xvar',
label = 'Select x-axis variable',
choices = c(xa[1:length(xa)]), selected=xa[2],
options = list(`style` = "btn-info"),
multiple = TRUE)
})
output$yvariable <- renderUI({
req(data_1())
ya<-colnames(data_1())
pickerInput(inputId = 'yvar',
label = 'Select y-axis variable',
choices = c(ya[1:length(ya)]), selected=ya[1],
options = list(`style` = "btn-info"),
multiple = FALSE)
})
lmModel <- reactive({
req(data_1(),input$xvar,input$yvar)
x <- as.numeric(data_1()[[as.name(input$xvar)]])
y <- as.numeric(data_1()[[as.name(input$yvar)]])
current_formula <- paste0(input$yvar, " ~ ", paste0(input$xvar, collapse = " + "))
current_formula <- as.formula(current_formula)
model <- lm(current_formula, data = data_1(), na.action=na.exclude)
return(model)
})
output$lmSummary <- renderPrint({
req(lmModel())
summary(lmModel())
})
output$tid <- renderPrint({
req(lmModel())
tidy(lmModel())
})
output$aug <- renderPrint({
req(lmModel())
augment(lmModel())
})
}
shinyApp(ui, server)
How the uploaded dataset could look like, for better explanation
data_set <- data.frame (Simulation_1 = c(1,2,3,4,5,6,7,8,9,10),
Simulation_2 = c(1,2,3,4,5,6,7,8,9,10),
Simulation_3 = c(1,2,3,4,5,6,7,8,9,10),
type = c("type_1", "type_2", "Type_5",
"type_1", "type_2", "Type_3",
"type_1", "type_2", "Type_1","Type_4")
)
Perhaps you are looking for this
library(shiny)
library(shinyWidgets)
library(DT)
library(dplyr)
library(nlme)
library(broom)
data_set <- data.frame (Simulation_1 = c(1,2,3,4,5,6,7,8,9,10),
Simulation_2 = c(1,2,3,4,5,6,7,8,9,10),
Simulation_3 = c(1,2,3,4,5,6,7,8,9,10),
type = c("type_1", "type_2", "Type_5",
"type_1", "type_2", "Type_3",
"type_1", "type_2", "Type_1","Type_4")
)
ui <- navbarPage("dd",
tabPanel("Reg",
sidebarPanel(
fileInput(
inputId = "filedata",
label = "Upload data. csv",
multiple = FALSE,
accept = c(".csv"),
buttonLabel = "Choosing ...",
placeholder = "No files selected yet"
),
uiOutput("col"),
uiOutput("type"),
uiOutput("xvariable"),
uiOutput("yvariable")
),
mainPanel(
DTOutput("tb1"),
fluidRow(
column(6, verbatimTextOutput('lmSummary')),
column(6,verbatimTextOutput("tid")),
column(6,verbatimTextOutput("aug"))
)
)
)
)
server <- function(input, output, session) {
data_0 <- reactive({
# req(input$filedata)
# inData <- input$filedata
# if (is.null(inData)){ return(NULL) }
# mydata <- read.csv(inData$datapath, header = TRUE, sep=",")
data_set
})
output$tb1 <- renderDT(head(data_1()))
output$col <- renderUI({
req(data_0())
selected = colnames(data_0())[length(colnames(data_0()))]
selectInput("mycol", "Choose column", choices = colnames(data_0()), selected = selected)
})
output$type <- renderUI({
req(data_0(),input$mycol)
selectInput("mytype", "Choose Type", choices = unique(data_0()[[input$mycol]]))
})
data_1 <- eventReactive(input$mytype, {
req(data_0(),input$mycol,input$mytype)
df <- data_0()
df$newvar <- df[[input$mycol]]
df %>% dplyr::filter(newvar %in% input$mytype) %>% dplyr::select(- c(newvar))
})
output$xvariable <- renderUI({
req(data_1())
xa<-colnames(data_1())
pickerInput(inputId = 'xvar',
label = 'Select x-axis variable',
choices = c(xa[1:length(xa)]), selected=xa[2],
options = list(`style` = "btn-info"),
multiple = TRUE)
})
output$yvariable <- renderUI({
req(data_1())
ya<-colnames(data_1())
pickerInput(inputId = 'yvar',
label = 'Select y-axis variable',
choices = c(ya[1:length(ya)]), selected=ya[1],
options = list(`style` = "btn-info"),
multiple = FALSE)
})
lmModel <- reactive({
req(data_1(),input$xvar,input$yvar)
x <- as.numeric(data_1()[[as.name(input$xvar)]])
y <- as.numeric(data_1()[[as.name(input$yvar)]])
current_formula <- paste0(input$yvar, " ~ ", paste0(input$xvar, collapse = " + "))
current_formula <- as.formula(current_formula)
model <- lm(current_formula, data = data_1(), na.action=na.exclude)
return(model)
})
output$lmSummary <- renderPrint({
req(lmModel())
summary(lmModel())
})
output$tid <- renderPrint({
req(lmModel())
tidy(lmModel())
})
output$aug <- renderPrint({
req(lmModel())
augment(lmModel())
})
}
shinyApp(ui, server)
I'm working on the large shiny app and I need to show a modal dialog and allow to perform some arithmetics operations in there, and when it is closed, it should return the data modified according to with de arithmetics to update data in the data table output. Furthermore, if the new dataset is selected, it should clear the fields, otherwise, if the modal is open again, should show the field loaded previously.
Since my app is very large, I want to create a modular code but when I call de module from bt_show_modal button in observeEvent, it does not do anything.
I've build the app in ui.r and server.r structure and works fine!
This is app code:
# APP CODE WITHOUT MODULE
library(shiny)
library(DT)
library(shinydashboard)
library(sortable)
doSum <- function(data, col1, col2, col_result) {
data[col_result] <- data[, col1] + data[, col2] # sum columns
return(data)
}
dataSet1 <- data.frame(
country = c("EEUU", "Italy", "Spain", "France"),
sales1 = c(500, 200, 1000, 1800),
sales2 = c(900, 100, 200, 1200))
dataSet2 <- data.frame(
city = c("Nwe York", "Rome", "Madrid", "Paris"),
sales1 = c(500, 200, 1000, 1800),
sales2 = c(900, 100, 200, 1200))
ui <- fluidPage(
fluidRow(
selectInput(inputId = "datasets",label = "Datasets",
choices = c("Countries", "Cities"),selected = "Countries"),
actionButton("bt_show_modal", "Show modal")),
dataTableOutput("preview1")
)
server <- function(input, output) {
values <- reactiveValues(df_wd = NULL)
values <- reactiveValues(g_l_oper1 = NULL)
values <- reactiveValues(g_l_oper2 = NULL)
modalReactive <- reactive({
modalDialog(
column(width = 6,
fluidRow(rank_list(text = "Fields",
labels = names(values$df_wd),
input_id = "l_source",
options = sortable_options(group = "list_group")))),
column(width = 6,
fluidRow(rank_list(text = "Variable 1",
labels = values$g_l_oper1,
input_id = "l_oper1",
options = sortable_options(group = "list_group"))),
fluidRow(rank_list(text = "Variable 2",
labels = values$g_l_oper2,
input_id = "l_oper2",
options = sortable_options(group = "list_group")))),
actionButton("btExecute", "Execute")
)
})
resetReactiveValues <- function() {
values$df_wd <- NULL
values$g_l_oper1 <- NULL
values$g_l_oper2 <- NULL
}
workData <- reactive({
if (!is.null(values$df_wd))
values$df_wd
else
if (input$datasets == "Countries")
values$df_wd <- dataSet1
else
values$df_wd <- dataSet2
})
observeEvent(input$bt_show_modal, {
showModal(modalReactive())
})
observeEvent(input$btExecute, {
values$df_wd <- doSum(workData(), input$l_oper1, input$l_oper2, "col_sum")
values$g_l_oper1 <- input$l_oper1
values$g_l_oper2 <- input$l_oper2
removeModal()
})
observeEvent(input$datasets, {
resetReactiveValues()
})
output$preview1 <- renderDataTable({
df <- workData()
req(df)
datatable(df)
})
}
shinyApp(ui = ui, server = server)
AND THIS IS THE MODULE IMPLEMEMTATION:
# MODULE CODE
doSum <- function(data, col1, col2, col_result) {
data[col_result] <- data[, col1] + data[, col2] # sum columns
return(data)
}
modalUI <- function(id) {
ns <- NS(id)
tagList(uiOutput(ns("sortable_object")))
}
modalServer <- function(id, data) {
moduleServer(id,
function(input, output, session) {
values <- reactiveValues(df_wd = NULL)
values <- reactiveValues(v_operand1 = NULL)
values <- reactiveValues(v_operand2 = NULL)
modalReactive <- reactive({
values$df_wd = data # Save parameter in reative global variable
ns <- session$ns # Name space
modalDialog(
column(width = 6,
fluidRow(rank_list(text = "Fields",
labels = names(values$df_wd),
input_id = ns("l_source"),
options = sortable_options(group = "list_group")))),
column(width = 6,
fluidRow(rank_list(text = "Variable 1",
labels = values$v_operand1,
input_id = ns("l_oper1"),
options = sortable_options(group = "list_group"))),
fluidRow(rank_list(text = "Variable 2",
labels = values$v_operand2,
input_id = ns("l_oper2"),
options = sortable_options(group = "list_group")))),
actionButton(ns("btExecute"), "Execute")
)
})
observe({
req(values$df_wd)
showModal(modalReactive())
})
observeEvent(input$btExecute, {
print("Execute")
values$df_wd <- doSum(values$df_wd,input$l_oper1,input$l_oper2,"col_sum")
values$v_operand1 <- input$l_oper1
values$v_operand2 <- input$l_oper2
removeModal()
})
return(reactive(values$df_wd)) # Dataframe with the new col "col_sum"
})
}
# APP CODE
library(shiny)
library(DT)
library(shinydashboard)
library(sortable)
dataSet1 <- data.frame(
country = c("EEUU", "Italy", "Spain", "France"),
sales1 = c(3500, 2100, 2000, 1500),
sales2 = c(900, 100, 200, 1200))
dataSet2 <- data.frame(
city = c("Nwe York", "Rome", "Madrid", "Paris"),
sales1 = c(500, 200, 1000, 1800),
sales2 = c(700, 300, 500, 1100))
ui <- fluidPage(
fluidRow(
selectInput(inputId = "datasets",label = "Datasets",
choices = c("Countries", "Cities"),selected = "Countries"),
actionButton("bt_show_modal", "Show modal")),
dataTableOutput("preview1"),
modalUI("modal_module")
)
server <- function(input, output) {
values <- reactiveValues(df_wd = NULL)
workData <- reactive({
if (!is.null(values$df_wd))
values$df_wd
else
if (input$datasets == "Countries")
values$df_wd <- dataSet1
else
values$df_wd <- dataSet2
})
modalReactive <- modalServer("modal_module", reactive(values$df_wd)) # Call the module
observeEvent(input$bt_show_modal, {
values$df_wd <- modalReactive()
})
observeEvent(input$datasets, {
values$df_wd <- NULL # Reset variable
})
output$preview1 <- renderDataTable({
df <- workData()
req(df)
datatable(df)
})
}
shinyApp(ui = ui, server = server)
I have two problems:
-First I cannot start the table showing only zeros or blank for that reason I've created a button that set's every thing to zero which kind of works but its not ideal.
-Secondly, I'm trying to calculate column sum for each column in a rhandontable but so far I havent been able to make it work.
I have been looking around for similar problems and I have found some code that looked promissing but in the end it only provided the sum for a single column or with some changes it would sum up all columns which is not what I'm after.
ui <- fluidPage(
rHandsontableOutput('table'),
textOutput('result'),
actionButton("recalc", "re-enter data")
)
season<-c("Spring","Summer","Autum","Winter")
server <- function(input,output,session)({
values <- reactiveValues(data = NULL) ## assign it with NULL
## button press resets now the data frame
observeEvent(input$recalc, {
values$data[] <- 0
})
## changes in numericInput sets all (!) new values
observe({
values$data <-data.frame(row.names=season,Lake=1:4,Beach=1:4, Garden=1:4,stringsAsFactors = FALSE)
})
observe({
if(!is.null(input$table))
values$data <- hot_to_r(input$table)
})
output$table <- renderRHandsontable({
req(values$data)
rhandsontable(values$data,rowHeaderWidth = 100)
})
})
shinyApp(ui = ui, server = server)
The expected results would be a 5th column with the sum of each column.
A starting table filled with zeros or blank.
If anyone could point me in the right direction it would be very much appreciated.
You can create empty cells with NA. Please check the following example to calculate colSums:
library(shiny)
library(rhandsontable)
ui <- fluidPage(
br(),
rHandsontableOutput('table'),
textOutput('result'),
br(),
actionButton("recalc", "re-enter data")
)
rowNames <- c("Spring", "Summer", "Autum", "Winter", "Sum")
defaultDF <- data.frame(
row.names = rowNames,
Lake = rep(NA_integer_, 5),
Beach = rep(NA_integer_, 5),
Garden = rep(NA_integer_, 5),
stringsAsFactors = FALSE
)
server <- function(input, output, session)
({
values <- reactiveValues(data = defaultDF) ## assign it with NULL
## button press resets now the data frame
observeEvent(input$recalc, {
values$data[] <- NA_integer_
})
observe({
req(input$table)
DF <- hot_to_r(input$table)
DF[setdiff(rowNames, "Sum"),]
DF["Sum",] <- colSums(DF[setdiff(rowNames, "Sum"),], na.rm = TRUE)
values$data <- DF
})
output$table <- renderRHandsontable({
req(values$data)
rhandsontable(values$data, rowHeaderWidth = 100) %>%
hot_row(nrow(values$data), readOnly = TRUE)
})
})
shinyApp(ui = ui, server = server)
Suppose I have the following shiny app:
library(shiny)
library(rhandsontable)
ui <- shinyUI(fluidPage(
titlePanel("Handsontable"),
sidebarLayout(
sidebarPanel(
helpText("Handsontable demo output. Column add/delete does work ",
"for tables with defined column properties, including type."),
radioButtons("useType", "Use Data Types", c("TRUE", "FALSE"))
),
mainPanel(
rHandsontableOutput("hot", width = 350)
)
)
))
server <- shinyServer(function(input, output, session) {
values = reactiveValues()
data = reactive({
if (!is.null(input$hot)) {
DF = hot_to_r(input$hot)
} else {
if (is.null(values[["DF"]]))
DF = data.frame(val = 1:10, bool = TRUE, nm = LETTERS[1:10],
dt = seq(from = Sys.Date(), by = "days", length.out = 10),
stringsAsFactors = F)
else
DF = values[["DF"]]
}
values[["DF"]] = DF
DF
})
output$hot <- renderRHandsontable({
DF = data()
if (!is.null(DF))
rhandsontable(DF, useTypes = as.logical(input$useType), stretchH = "all")
})
})
# Run the application
shinyApp(ui = ui, server = server)
How can I disable editing for the first two columns?
The whole table and individual columns can to set to readOnly to prevent the user from making changes.(http://jrowen.github.io/rhandsontable/#read-only)
library(shiny)
library(rhandsontable)
ui <- shinyUI(fluidPage(
titlePanel("Handsontable"),
sidebarLayout(
sidebarPanel(
helpText("Handsontable demo output. Column add/delete does work ",
"for tables with defined column properties, including type."),
radioButtons("useType", "Use Data Types", c("TRUE", "FALSE"))
),
mainPanel(
rHandsontableOutput("hot", width = 350)
)
)
))
server <- shinyServer(function(input, output, session) {
values = reactiveValues()
data = reactive({
if (!is.null(input$hot)) {
DF = hot_to_r(input$hot)
} else {
if (is.null(values[["DF"]]))
DF = data.frame(val = 1:10, bool = TRUE, nm = LETTERS[1:10],
dt = seq(from = Sys.Date(), by = "days", length.out = 10),
stringsAsFactors = F)
else
DF = values[["DF"]]
}
values[["DF"]] = DF
DF
})
output$hot <- renderRHandsontable({
DF = data()
if (!is.null(DF))
rhandsontable(DF, useTypes = as.logical(input$useType), stretchH = "all") %>%
hot_col("val", readOnly = TRUE) %>%
hot_col("bool",readOnly = TRUE )
})
})
# Run the application
shinyApp(ui = ui, server = server)