Good Afternoon, right now I am Working on an app where the user can choose the length of a vector (up to 30 values) and then fill those vectors in rhandsontable to make different kind of plots, so far i have managed to do it but it only works with only the first cell of each column that is why i like to ask how do I make the app to take into account all the values of the vectors, also i was wondering is there a way to also introduce characters in case you want to make labels for the histogram for instance.
Here is the code
type or paste code here
library(shiny)
library(DT)
library(shinydashboard)
library(rhandsontable)
library(devtools)
library(ggplot2)
library(excelR)
library(plotly)
library(shinyjs)
library(dplyr)
#Vectores Para Graficar
x2<-data.frame( t(replicate(2,0))); y2<-data.frame( x2 );x3<-data.frame( t(replicate(3,0)) ); y3<-data.frame(x3);x4<-data.frame(t(replicate(4,0))); y4<-data.frame(x4);x5<-data.frame(t(replicate(5,0))); y5<-data.frame(x5);x6<-data.frame(t(replicate(6,0))); y6<-data.frame(x6);x7<-data.frame(t(replicate(7,0))); y7<-data.frame(x7);x8<-data.frame(t(replicate(8,0))); y8<-data.frame(x8);x9<-data.frame(t(replicate(9,0))); y9<-data.frame(x9);x10<-data.frame(t(replicate(10,0))); y10<-data.frame(x10);
x11<-data.frame(t(replicate(11,0)) ); y11<-data.frame(x11);x12<-data.frame(t(replicate(12,0))); y12<-data.frame(x12);x13<-data.frame(t(replicate(13,0))); y13<-data.frame(x13);x14<-data.frame(t(replicate(14,0))); y14<-data.frame(x14);x15<-data.frame(t(replicate(15,0))); y15<-data.frame(x15);x16<-data.frame(t(replicate(16,0))); y16<-data.frame(x16);x17<-data.frame(t(replicate(17,0))); y17<-data.frame(x17);x18<-data.frame(t(replicate(18,0))); y18<-data.frame(x18);x19<-data.frame(t(replicate(19,0))); y19<-data.frame(x19);x20<-data.frame(t(replicate(20,0))); y20<-data.frame(x20);x21<-data.frame(t(replicate(21,0))); y21<-data.frame(x21);
x22<-data.frame(t(replicate(22,0))); y22<-data.frame(x22);x23<-data.frame(t(replicate(23,0))); y23<-data.frame(x23);x24<-data.frame(t(replicate(24,0))); y24<-data.frame(x24);x25<-data.frame(t(replicate(25,0))); y25<-data.frame(x25);x26<-data.frame(t(replicate(26,0))); y26<-data.frame(x26);x27<-data.frame(t(replicate(27,0))); y27<-data.frame(x27);x28<-data.frame(t(replicate(28,0))); y28<-data.frame(x28);x29<-data.frame(t(replicate(29,0))); y29<-data.frame(x29);x30<-data.frame(t(replicate(30,0))); y30<-data.frame(x30);
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
menuItem(selectInput(inputId = "S.Table2", label = "choose the Lenght of the vectors to plot (Up to Lenght 30)",
choices = c("2","3","4","5","6","7","8","9","10",
"11","12","13","14","15","16","17","18","19","20",
"21","22","23","24","25","26","27","28","29","30")
,selected ="3"),icon=icon("list")),
tags$hr(),
radioButtons("choice2","Choose a type of plot", choices=c("Histogram" =1,"Pie-chart" = 2,
"Plot" = 3,"Time Series" = 4 , "Donut chart" = 5))
),
# Show a plot of the generated distribution
mainPanel(
rHandsontableOutput("tablex"),
tags$hr(),
rHandsontableOutput("tabley"),
plotlyOutput("plot_one")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output,session) {
valuesx = reactiveValues()
valuesx[["2"]] <- x2;valuesx[["3"]] <- x3;valuesx[["4"]] <- x4;valuesx[["5"]] <- x5;valuesx[["6"]] <- x6;valuesx[["7"]] <- x7;valuesx[["8"]] <- x8;valuesx[["9"]] <- x9;valuesx[["10"]] <- x10
valuesx[["11"]] <- x11;valuesx[["12"]] <- x12;valuesx[["13"]] <- x13;valuesx[["14"]] <- x14;valuesx[["15"]] <- x15;valuesx[["16"]] <- x16;valuesx[["17"]] <- x17;valuesx[["18"]] <- x18;valuesx[["19"]] <- x19
valuesx[["20"]] <- x20;valuesx[["21"]] <- x21;valuesx[["22"]] <- x22;valuesx[["23"]] <- x23;valuesx[["24"]] <- x24;valuesx[["25"]] <- x25;valuesx[["26"]] <- x26;valuesx[["27"]] <- x27;valuesx[["28"]] <- x28
valuesx[["29"]] <- x29;valuesx[["30"]] <- x30
valuesy = reactiveValues()
valuesy[["2"]] <- y2;valuesy[["3"]] <- y3;valuesy[["4"]] <- y4;valuesy[["5"]] <- y5;valuesy[["6"]] <- y6;valuesy[["7"]] <- y7;valuesy[["8"]] <- y8;valuesy[["9"]] <- y9;valuesy[["10"]] <- y10
valuesy[["11"]] <- y11;valuesy[["12"]] <- y12;valuesy[["13"]] <- y13;valuesy[["14"]] <- y14;valuesy[["15"]] <- y15;valuesy[["16"]] <- y16;valuesy[["17"]] <- y17;valuesy[["18"]] <- y18;valuesy[["19"]] <- y19
valuesy[["20"]] <- y20;valuesy[["21"]] <- y21;valuesy[["22"]] <- y22;valuesy[["23"]] <- y23;valuesy[["24"]] <- y24;valuesy[["25"]] <- y25;valuesy[["26"]] <- y26;valuesy[["27"]] <- y27;valuesy[["28"]] <- y28
valuesy[["29"]] <- y29;valuesy[["30"]] <- y30
observe({
if (!is.null(input$tablex)) {
temp <- hot_to_r(input$tablex)
#temp <- input$table
if (isolate(input$S.Table2) == "2") {
valuesx[["2"]] <- temp
} else if ( isolate(input$S.Table2) == "3" ) {
valuesx[["3"]] <- temp
} else if ( isolate(input$S.Table2) == "4" ) {
valuesx[["4"]] <- temp
} else if ( isolate(input$S.Table2) == "5" ) {
valuesx[["5"]] <- temp
} else if ( isolate(input$S.Table2) == "6" ) {
valuesx[["6"]] <- temp
} else if ( isolate(input$S.Table2) == "7" ) {
valuesx[["7"]] <- temp
} else if ( isolate(input$S.Table2) == "8" ) {
valuesx[["8"]] <- temp
} else if ( isolate(input$S.Table2) == "9" ) {
valuesx[["9"]] <- temp
} else if ( isolate(input$S.Table2) == "10" ) {
valuesx[["10"]] <- temp
} else if ( isolate(input$S.Table2) == "11" ) {
valuesx[["11"]] <- temp
} else if ( isolate(input$S.Table2) == "12" ) {
valuesx[["12"]] <- temp
} else if ( isolate(input$S.Table2) == "13" ) {
valuesx[["13"]] <- temp
} else if ( isolate(input$S.Table2) == "14" ) {
values[["14"]] <- temp
} else if ( isolate(input$S.Table2) == "15" ) {
valuesx[["15"]] <- temp
} else if ( isolate(input$S.Table2) == "16" ) {
valuesx[["16"]] <- temp
} else if ( isolate(input$S.Table2) == "17" ) {
valuesx[["17"]] <- temp
} else if ( isolate(input$S.Table2) == "18" ) {
valuesx[["18"]] <- temp
} else if ( isolate(input$S.Table2) == "19" ) {
valuesx[["19"]] <- temp
} else if ( isolate(input$S.Table2) == "20" ) {
valuesx[["20"]] <- temp
} else if ( isolate(input$S.Table2) == "22" ) {
valuesx[["22"]] <- temp
} else if ( isolate(input$S.Table2) == "23" ) {
valuesx[["23"]] <- temp
} else if ( isolate(input$S.Table2) == "24" ) {
valuesx[["24"]] <- temp
} else if ( isolate(input$S.Table2) == "25" ) {
valuesx[["25"]] <- temp
} else if ( isolate(input$S.Table2) == "26" ) {
valuesx[["26"]] <- temp
} else if ( isolate(input$S.Table2) == "27" ) {
valuesx[["27"]] <- temp
} else if ( isolate(input$S.Table2) == "28" ) {
valuesx[["28"]] <- temp
} else if ( isolate(input$S.Table2) == "29" ) {
valuesx[["29"]] <- temp
} else if ( isolate(input$S.Table2) == "30" ) {
valuesx[["30"]] <- temp
}
}
})
#Permite cambiar entre vectores para la variable x
TablaD2<- reactive({
if (input$S.Table2 == "2") {
TablaD2 <- valuesx[["2"]]
} else if (input$S.Table2 == "3"){
TablaD2 <- valuesx[["3"]]
} else if (input$S.Table2 == "4"){
TablaD2 <- valuesx[["4"]]
} else if (input$S.Table2 == "5"){
TablaD2 <- valuesx[["5"]]
} else if (input$S.Table2 == "6"){
TablaD2 <- valuesx[["6"]]
} else if (input$S.Table2 == "7"){
TablaD2 <- valuesx[["7"]]
} else if (input$S.Table2 == "8"){
TablaD2 <- valuesx[["8"]]
} else if (input$S.Table2 == "9"){
TablaD2 <- valuesx[["9"]]
} else if (input$S.Table2 == "10"){
TablaD2 <- valuesx[["10"]]
} else if (input$S.Table2 == "11"){
TablaD2 <- valuesx[["11"]]
} else if (input$S.Table2 == "12"){
TablaD2 <- valuesx[["12"]]
} else if (input$S.Table2 == "13"){
TablaD2 <- valuesx[["13"]]
} else if (input$S.Table2 == "14"){
TablaD2 <- valuesx[["14"]]
} else if (input$S.Table2 == "15"){
TablaD2 <- valuesx[["15"]]
} else if (input$S.Table2 == "16"){
TablaD2 <- valuesx[["16"]]
} else if (input$S.Table2 == "17"){
TablaD2 <- valuesx[["17"]]
} else if (input$S.Table2 == "18"){
TablaD2 <- valuesx[["18"]]
} else if (input$S.Table2 == "19"){
TablaD2 <- valuesx[["19"]]
} else if (input$S.Table2 == "19"){
TablaD2 <- valuesx[["19"]]
} else if (input$S.Table2 == "20"){
TablaD2 <- valuesx[["20"]]
} else if (input$S.Table2 == "21"){
TablaD2 <- valuesx[["21"]]
} else if (input$S.Table2 == "22"){
TablaD2 <- valuesx[["22"]]
} else if (input$S.Table2 == "23"){
TablaD2 <- valuesx[["23"]]
} else if (input$S.Table2 == "24"){
TablaD2 <- valuesx[["24"]]
} else if (input$S.Table2 == "25"){
TablaD2 <- valuesx[["25"]]
} else if (input$S.Table2 == "26"){
TablaD2 <- valuesx[["26"]]
} else if (input$S.Table2 == "27"){
TablaD2 <- valuesx[["27"]]
} else if (input$S.Table2 == "28"){
TablaD2 <- valuesx[["28"]]
} else if (input$S.Table2 == "29"){
TablaD2 <- valuesx[["29"]]
} else if (input$S.Table2 == "30"){
TablaD2 <- valuesx[["30"]]
}
TablaD2
})
output$tablex <-renderRHandsontable({
if(is.null( TablaD2() )){return()}
rhandsontable( TablaD2() , showToolbar=TRUE , search=TRUE , rowDrag = TRUE,
columnDrag = TRUE, rowResize = TRUE, minDimension = c(100, 100))
})
observe({
if (!is.null(input$tabley)) {
temp <- hot_to_r(input$tabley)
#temp <- input$table
if (isolate(input$S.Table2) == "2") {
valuesy[["2"]] <- temp
} else if ( isolate(input$S.Table2) == "3" ) {
valuesy[["3"]] <- temp
} else if ( isolate(input$S.Table2) == "4" ) {
valuesy[["4"]] <- temp
} else if ( isolate(input$S.Table2) == "5" ) {
valuesy[["5"]] <- temp
} else if ( isolate(input$S.Table2) == "6" ) {
valuesy[["6"]] <- temp
} else if ( isolate(input$S.Table2) == "7" ) {
valuesy[["7"]] <- temp
} else if ( isolate(input$S.Table2) == "8" ) {
valuesy[["8"]] <- temp
} else if ( isolate(input$S.Table2) == "9" ) {
valuesy[["9"]] <- temp
} else if ( isolate(input$S.Table2) == "10" ) {
valuesy[["10"]] <- temp
} else if ( isolate(input$S.Table2) == "11" ) {
valuesy[["11"]] <- temp
} else if ( isolate(input$S.Table2) == "12" ) {
valuesy[["12"]] <- temp
} else if ( isolate(input$S.Table2) == "13" ) {
valuesy[["13"]] <- temp
} else if ( isolate(input$S.Table2) == "14" ) {
valuesy[["14"]] <- temp
} else if ( isolate(input$S.Table2) == "15" ) {
valuesy[["15"]] <- temp
} else if ( isolate(input$S.Table2) == "16" ) {
valuesy[["16"]] <- temp
} else if ( isolate(input$S.Table2) == "17" ) {
valuesy[["17"]] <- temp
} else if ( isolate(input$S.Table2) == "18" ) {
valuesy[["18"]] <- temp
} else if ( isolate(input$S.Table2) == "19" ) {
valuesy[["19"]] <- temp
} else if ( isolate(input$S.Table2) == "20" ) {
valuesy[["20"]] <- temp
} else if ( isolate(input$S.Table2) == "22" ) {
valuesy[["22"]] <- temp
} else if ( isolate(input$S.Table2) == "23" ) {
valuesy[["23"]] <- temp
} else if ( isolate(input$S.Table2) == "24" ) {
valuesy[["24"]] <- temp
} else if ( isolate(input$S.Table2) == "25" ) {
valuesy[["25"]] <- temp
} else if ( isolate(input$S.Table2) == "26" ) {
valuesy[["26"]] <- temp
} else if ( isolate(input$S.Table2) == "27" ) {
valuesy[["27"]] <- temp
} else if ( isolate(input$S.Table2) == "28" ) {
valuesy[["28"]] <- temp
} else if ( isolate(input$S.Table2) == "29" ) {
valuesy[["29"]] <- temp
} else if ( isolate(input$S.Table2) == "30" ) {
valuesy[["30"]] <- temp
}
}
})
#Permite cambiar entre vectores para la variable y
TablaD3<- reactive({
if (input$S.Table2 == "2") {
TablaD3 <- valuesy[["2"]]
} else if (input$S.Table2 == "3"){
TablaD3 <- valuesy[["3"]]
} else if (input$S.Table2 == "4"){
TablaD3 <- valuesy[["4"]]
} else if (input$S.Table2 == "5"){
TablaD3 <- valuesy[["5"]]
} else if (input$S.Table2 == "6"){
TablaD3 <- valuesy[["6"]]
} else if (input$S.Table2 == "7"){
TablaD3 <- valuesy[["7"]]
} else if (input$S.Table2 == "8"){
TablaD3 <- valuesy[["8"]]
} else if (input$S.Table2 == "9"){
TablaD3 <- valuesy[["9"]]
} else if (input$S.Table2 == "10"){
TablaD3 <- valuesy[["10"]]
} else if (input$S.Table2 == "11"){
TablaD3 <- valuesy[["11"]]
} else if (input$S.Table2 == "12"){
TablaD3 <- valuesy[["12"]]
} else if (input$S.Table2 == "13"){
TablaD3 <- valuesy[["13"]]
} else if (input$S.Table2 == "14"){
TablaD3 <- valuesy[["14"]]
} else if (input$S.Table2 == "15"){
TablaD3 <- valuesy[["15"]]
} else if (input$S.Table2 == "16"){
TablaD3 <- valuesy[["16"]]
} else if (input$S.Table2 == "17"){
TablaD3 <- valuesy[["17"]]
} else if (input$S.Table2 == "18"){
TablaD3 <- valuesy[["18"]]
} else if (input$S.Table2 == "19"){
TablaD3 <- valuesy[["19"]]
} else if (input$S.Table2 == "19"){
TablaD3 <- valuesy[["19"]]
} else if (input$S.Table2 == "20"){
TablaD3 <- valuesy[["20"]]
} else if (input$S.Table2 == "21"){
TablaD3 <- valuesy[["21"]]
} else if (input$S.Table2 == "22"){
TablaD3 <- valuesy[["22"]]
} else if (input$S.Table2 == "23"){
TablaD3 <- valuesy[["23"]]
} else if (input$S.Table2 == "24"){
TablaD3 <- valuesy[["24"]]
} else if (input$S.Table2 == "25"){
TablaD3 <- valuesy[["25"]]
} else if (input$S.Table2 == "26"){
TablaD3 <- valuesy[["26"]]
} else if (input$S.Table2 == "27"){
TablaD3 <- valuesy[["27"]]
} else if (input$S.Table2 == "28"){
TablaD3 <- valuesy[["28"]]
} else if (input$S.Table2 == "29"){
TablaD3 <- valuesy[["29"]]
} else if (input$S.Table2 == "30"){
TablaD3 <- valuesy[["30"]]
}
TablaD3
})
output$tabley <-renderRHandsontable({
if(is.null( TablaD3() )){return()}
rhandsontable( TablaD3() , showToolbar=TRUE , search=TRUE , rowDrag = TRUE,
columnDrag = TRUE, rowResize = TRUE, minDimension = c(100, 100))
})
output$plot_one <- renderPlotly({
plot_ly(
data = TablaD2(),
x = ~TablaD2()[,1,ncol(TablaD2())],
y = ~TablaD3()[,1,ncol(TablaD3())],
type = "bar"
) %>%
layout(title = "Histogram",
xaxis = list(title = ""),
yaxis = list(title = "")
)
})
}
# Run the application
shinyApp(ui = ui, server = server)
Thanks for your time and help