Creating new ui variables from server output

Hello!

Here is a nice set of code that works fine:

 xa.df <- data.frame(x=1:10,y1=rnorm(10),y2=rexp(10))
 library(openxlsx)
 write.xlsx(xa.df,file="test1b.xlsx")

and the shiny code is:

library(shiny)
library(readxl)
library(shinyjs)
library(ggplot2)

runApp(
    list(
        ui = fluidPage(
	useShinyjs(),
	div(
	   id="form",
	
            titlePanel("Use readxl"),
            sidebarLayout(
                sidebarPanel(
                    fileInput('file1', 'Choose xlsx file',
                              accept = c(".xlsx")
                              ),
		     textInput("x1","Enter the x Variable",value=" "),
		     textInput("y1","Enter the y Variable",value=" ")
		     ),
      actionButton("resetAll", "Draw the plot"))
                    ),

                mainPanel(

		     verbatimTextOutput("contents"),
		     plotOutput("plot1"))


            ),
        server = function(input, output,session){

       text_reactive <- eventReactive(input$resetAll, {
       print("in event")
       print(str(dist()))
       print(names(dist()))
       print(input$x1)
       myx1 <- gsub(" ","",input$x1)
       myy1 <- gsub(" ","",input$y1)
       print(which(myx1==names(dist())))
       x4 <- which(myx1==names(dist()))
       x5 <- which(myy1==names(dist()))
       x6 <- data.frame(x=dist()[[x4]],y=dist()[[x5]],z=1:10)
       print(str(x6))
       x6
}
)
	       dist <- reactive({

                inFile <- input$file1

                if(is.null(inFile))
                    return(NULL)
                file.rename(inFile$datapath,
                          paste(inFile$datapath, ".xlsx", sep=""))
                read_excel(paste(inFile$datapath, ".xlsx", sep=""), 1)
                x3 <- as.data.frame(read_excel(paste(inFile$datapath, ".xlsx", sep=""), 1))
		return(x3)
		 })
		 output$contents <- renderText({
		 names(dist())
		 		 })
		 output$plot1 <-
		 renderPlot({ggplot(text_reactive(),
		 aes(x=unlist(text_reactive()[1]),
		 y=unlist(text_reactive()[2]))) +
		 geom_line() +
		 ggtitle("test for plotting") +
		 xlab(input$x1) + ylab(input$y1)
		 })
		})
)

Works like a charm. My question is: is there a way to take the output from the names of the data frame created from the Excel file and have those be a selectInput variable, please?

Thanks,
Erin

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.