0
나는 간단한 반짝 이는 애플 리케이션을 수행하도록 요청 받았습니다. 다음 코드를 가지고 있습니다 :tabpanel 반짝 이는 애플 리케이션 내의 R
library(shiny)
ui <- fluidPage(
tabsetPanel(
tabPanel(title = "Central Limit Theorem",
sliderInput(inputId = "num", label = "Choose a sample size",
value = 5, min = 1, max = 50),
plotOutput(outputId = "hist")
)
,
tabPanel(title = "BMI prediction",
pageWithSidebar(
# Application title
headerPanel("BMI prediction"),
sidebarPanel(
numericInput('wt', 'Weight in Pounds', 90, min = 50, max = 200),
submitButton('Submit'),
numericInput('ht', 'Height in Inches', 60, min = 50, max = 85),
submitButton('Submit')
),
mainPanel(
h3('Results of prediction'),
h4('Your weight is'),
verbatimTextOutput("inputValue1"),
h4('Your height is'),
verbatimTextOutput("inputValue2"),
h4('Which resulted in a BMI of '),
verbatimTextOutput("prediction")
)
)
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$hist <- renderPlot({
par(mfrow = c(1,2))
r <- 10000
samp <- matrix(rexp(n=(input$num)*r, rate = 2), nrow = r)
sample.means <- apply(samp,1,mean)
hist(sample.means,col="purple", main="Sampling Distribution of the Sample Mean",
xlab = "Sample Mean")
qqnorm(sample.means, col = "purple")
})
bmi_calc <- function(weight, height) (weight/height^2)*703
output$inputValue1 <- renderPrint({input$wt})
output$inputValue2 <- renderPrint({input$ht})
output$prediction <- renderPrint({bmi_calc(input$wt, input$ht)})
}
shinyApp(ui = ui, server = server)
어떤 이유로 인해 첫 번째 탭의 히스토그램이 슬라이더에 응답하지 않습니다. 두 번째 탭을 포함하지 않으면 정상적으로 작동합니다.
굉장! 나는 각 탭에 업데이트 버튼을 포함 시켰기 때문에 사용자는 각 탭의 결과를 별도로 제어 할 수있는 느낌을 갖게되었습니다. 감사. – user3922546