ui code:
===
library(shiny)
shinyUI(
# Use a fluid Bootstrap layout
fluidPage(
# Generate a row with a sidebar
sidebarLayout(
# Define the sidebar with one input
sidebarPanel(
sliderInput("capacity", "Current Capacity:",
min=0, max=100, value=10),
c(list(
textInput("service", "Service Component Name", ""),
actionButton("addbtn", "Add Component"))),
#lapply(seq(10), function(i) uiOutput(paste0("ui", i)))
br(),
br(),
br(),
br(),
br(),
actionButton("calcbtn", "Calculate Projection")
),
# Create a spot for the barplot
mainPanel(
textInput("inputWork","Volume", width="200px"),
textInput("inputGrowth","Growth Rate", width="100px"),
lapply(seq(10), function(i) uiOutput(paste0("ui", i)))
#tags$p("Web"),
#verbatimTextOutput("input_type_text")
)
)
)
)
server code:
server <- function(input, output)
{
observeEvent(input$addbtn, {
n <- isolate(input$addbtn)
if (n == 0) return()
# create n-th pair of text input and output
output[[paste0("ui", n)]] <- renderUI(
list(textInput(paste0("textin", n), isolate(input$service)),
textOutput(paste0("textout", n))))
# display something in the output
output[[paste0("textout", n)]] <- renderText({
work<-as.numeric(input$inputWork)
growth<-as.numeric(input$inputGrowth)
print(growth)
#paste("projection", (100+growth)*as.numeric(input[[paste0("textin", n)]]))
})
})
observeEvent(input$calcbtn, {
n <- isolate(input$calcbtn)
if (n == 0) return()
output[[paste0("textout", n)]] <- renderText({
work<-as.numeric(input$inputWork)
growth<-as.numeric(input$inputGrowth)
project<-growth+as.numeric(input$service)
print(growth)
print(project)
paste("projection", ((1+growth/100)*as.numeric(input[[paste0("textin", n)]])))
})
})
}
This is what I am trying to do. This code will have an initial text box and submit button. User put a text in the first input text, clicks the submitbutton, a new text generated in the main panel. A user can do this multiple times to create multiple textInput boxes in the main panel.
I also have a static another inputText box labeled Workload on top of the main panel.
So, this is what I am trying to do:
- User will insert data in workload textIntut (it needs to numeric).
- User will insert data into other dynamically generated textInput boxes (all need to be numeric).
- I will get the values from workload and all the other textboxes, do some calculations and projections and display data next to each dynamically generated textInput boxes, it would be great if I could insert textboxes next to the ones generate to display my output.
For example, I have data in my workload, I have generated Web_server, App_server textInput boxes. I will take the data from workload and devided that by the data in web_server, and display it next to the web_server textInput box (show the data in a textbox), do the same for the app_server textInput box.
Any ideas how I could do this in shiny? This is the image what I am trying to accomplish. Given the Workload Growth Rate taken from the user and other inputs from the User Input section, I will have to calculate and populate the respective textboxes.
calcbtn
is defined somewhere in the UI, what is the expected behavior when you click it? Does this update all textOutputs dynamically created, or only one of them? – Kota MoritextOutput
one by one. Also, I guess from the code, that thetextOutput
won't be updated any more even if you change thetextInput
and click thecalcbtn
again. Now, what is your expected behavior when thecalcbtn
is clicked? – Kota Moriui.R
andserver.R
separately. With them people have to make a folder, and make two files just to try your code. Instead, prepare a set of codes that one can simply copy onto his or her editor and run it. – Kota Mori