Меня попросили сделать простое блестящее приложение. У меня есть следующий код: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