闪亮/ R:输出不显示

时间:2016-05-11 12:06:06

标签: r shiny

所以我正在尝试制作税务计算应用。在侧边栏中,我使用tabsetPanel显示两个面板,这些面板具有与个人相关的不同输入,然后是税率。

mainPanel也将使用tabsetPanel,我计划绘制图表等。我有一个似乎没有工作的更新按钮。

ui.R

看起来像这样:

shinyUI(fluidPage(
titlePanel("flatTax"),
sidebarLayout(
sidebarPanel(
  h1("Flat Tax Calculator"),
  helpText("Input your information below and see how a flat tax could
affect your tax bill."),

  #Individual Specific Variables
  tabsetPanel(
    tabPanel("You",
    numericInput(inputId = "incomeNum",
                label = "Your annual income:",
                value = 0
    ),

    textInput(inputId = "testText",
              label = "Test Input"
              ),
    ),

    tabPanel("Tax Settings", 
    sliderInput(inputId = "basicIncome", 
                label = "Choose a monthly basic income", 
                value = 600, min = 0, max = 1200, step = 50
    ),

    sliderInput(inputId = "taxFree", 
                label = "Choose a tax free allowance", 
                value = 10000, min = 0, max = 20000, step = 250
    ),

    sliderInput(inputId = "flatIncomeTax", 
                label = "Choose a flat tax rate", 
                value = 50, min = 0, max = 100, step = 1
    ),

    sliderInput(inputId = "flatPropertyTax", 
                label = "Choose a land value tax rate", 
                value = 1, min = 0, max = 100, step = 1
  )),

  # Action Button
  actionButton(inputId = "updateButton", 
               label = "Update"),
  plotOutput("text")
)
),


mainPanel(
  tabsetPanel(
    tabPanel("Summary",
      h3("Test Output", textOutput("test"),
      h3("Your new income tax bill is:", textOutput("incomeFT")),
      h3("Your new property tax bill is:", textOutput("propertyFT")),
      textOutput("annualBasicIncome")
        )
        ),
    tabPanel("Graphs",
          h3("Placeholder"),
          h3("Holding the place"),
          h3("Plaice holster")   
        )
      )
)
)
))


server.R

看起来像这样:

shinyServer(
function(input, output) {


#action button stuff
incomeFT <- eventReactive(input$updateButton, {
  ((input$incomeNum-input$taxFree)/100*input$flatIncomeTax)
})

output$incomeFT <- renderPrint({
  incomeFT()
})

propertyFT <- eventReactive(input$updateButton, {
  input$propertyNum/100*input$flatPropertyTax
})

output$propertyFT <- renderPrint({
  propertyFT()
})    

annualBasicIncome <- eventReactive(input$updateButton, {
  switch(as.numeric(input$relStat),
         return((input$basicIncome*12)+((input$basicIncome*12)*input$childNum)),
         return((2*(input$basicIncome*12))+((input$basicIncome*12)*input$childNum))
  )
  })

output$annualBasicIncome <- renderPrint({
  annualBasicIncome()
})

test <- eventReactive(input$updateButton, {
  input$testText
})

output$test <- renderText({
  test()
})
})

没有反应性它似乎有用,但按钮使它不会分散使用的注意力。我尝试过使用verbatimTextOutput而不是textOutput,但是在主面板上发送的灰色条没有输出。

请帮忙吗?

1 个答案:

答案 0 :(得分:0)

出于某种原因,actionButtontabsetPanel内无效。如果你把它放在它之外(和sidebarPanel里面)它会起作用。我建议您尝试为每个actionButton使用一个tabPanel。我没试过,但我相信它应该有效。如果您尝试,请告诉我结果。

干杯。