library(shiny)
library(DT)
shinyUI(fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30),
textOutput("textres")
),
mainPanel(
DT::dataTableOutput("testDT")
)
)
))
library(shiny)
library(DT)
shinyServer(function(input, output) {
output$testDT <- DT::renderDataTable({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
h = hist(x, breaks = bins, col = 'darkgray', border = 'white')
res = cbind(h$counts, h$density, h$mids)
colnames(res) <- c("counts", "density", "mids")
res = data.frame(res)
res[,"numericinput"] <- ""
sapply(1:nrow(res), FUN = function(i) {
res$numericinput[i] <<- as.character(numericInput(paste0("num", i), "", value = 5, min = 0, max = 10, step = 0.01))
})
datatable(res, escape = 4)
})
output$textres <- renderText({
h = hist(x, breaks = bins, col = 'darkgray', border = 'white')
res = ""
# sapply(1:length(h$counts), FUN = function(i) {
# res <<- paste(res, input[[paste0("num",i)]])
# })
# res
paste(names(input))
})
})## DT Server Side# multi select is not suggested for server-side. when user changes page the seleced records are forgotten
library(shiny)library(DT)library(data.table)
x <- faithful[, 2]
shinyApp( ui = fluidPage( titlePanel("Old Faithful Geyser Data"),
sidebarLayout( sidebarPanel( sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30), textOutput("textres") ), mainPanel( DT::dataTableOutput("testDT") ) ) ), server = function(input, output, session) { bins <-reactive(seq(min(x), max(x), length.out = input$bins + 1)) output$testDT <- DT::renderDataTable({ # draw the histogram with the specified number of bins h = hist(x, breaks = bins(), col = 'darkgray', border = 'white') res = cbind(h$counts, h$density, h$mids) colnames(res) <- c("counts", "density", "mids") res = data.frame(res) res[,"numericinput"] <- "" #creates input fields sapply(1:nrow(res), FUN = function(i) { res$numericinput[i] <<- as.character(numericInput(paste0("num", i), "", value = 5, min = 0, max = 10, step = 0.01)) }) datatable(res, escape = 4) }) output$textres <- renderText({ h = hist(x, breaks = bins(), col = 'darkgray', border = 'white') browser() res = "" # sapply(1:length(h$counts), FUN = function(i) { # res <<- paste(res, input[[paste0("num",i)]]) # }) # res paste(names(input)) })})
library(shiny)
library(DT)
shinyServer(function(input, output) {
output$testDT <- DT::renderDataTable({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
h = hist(x, breaks = bins, col = 'darkgray', border = 'white')
res = cbind(h$counts, h$density, h$mids)
colnames(res) <- c("counts", "density", "mids")
res = data.frame(res)
res[,"numericinput"] <- ""
sapply(1:nrow(res), FUN = function(i) {
res$numericinput[i] <<- as.character(numericInput(paste0("num", i), "", value = i, min = 0, max = 10, step = 0.01))
})
datatable(res, escape = 4)
})
output$textres <- renderText({
paste(names(input))
})
})# need the development version of shiny due to https://github.com/rstudio/shiny/pull/857
if (packageVersion('shiny') < '0.12.0.9003')
devtools::install_github('rstudio/shiny')
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(
# add slider to control number of rows shown in table
sliderInput("slider_num_rows", "Num Rows", min = 0, max = 100, value = 10),
# use slider to control number of rows shown in table
res[1:input$slider_num_rows,], server = FALSE, escape = FALSE, options = list(
preDrawCallback = JS('function() {
Shiny.unbindAll(this.api().table().node()); }'),
drawCallback = JS('function() {
Shiny.bindAll(this.api().table().node()); } ')
)
)
# print the values of inputs
output$x2 = renderPrint({
data.frame(v1 = shinyValue('v1_', 100), v2 = shinyValue('v2_', 100))
})
}
)