view ShinyEB.R @ 8:7db5a949ba24

入力に意味が無い場合にチェックボックスを表示しないようにする
author uncorrelated zombie <uncorrelated@yahoo.co.jp>
date Sun, 30 Oct 2022 11:54:06 +0900
parents 9535740da224
children 6796c62e3a12
line wrap: on
line source

source("loadLib.R")
source("EdgeworthBox.R")

loadLib("nleqslv", "shiny")

ui <- fluidPage(
    titlePanel("Edgeworth Box"),

    sidebarLayout(
        sidebarPanel(
            sliderInput("A",
                "initial amount of goods A of person 1",
                min = 0.01,
                max = 0.99,
                value = 0.8), 
            sliderInput("B",
                "initial amount of goods B of person 1",
                min = 0.01,
                max = 0.99,
                value = 0.3),
            checkboxInput("isIP", "Initial Point", TRUE),
            checkboxInput("isIC_I", "Indiffrent Curves pass through the Initial Point", TRUE),
            # チェックボックスありとなしの見えないタブを作る
            tabsetPanel(
                id = "tab4core",
                type = "hidden",
                tabPanel("true",
                    checkboxInput("isCore", "Core", TRUE)
                ),
                tabPanel("false")
            ),
            checkboxInput("isIC_E", "Indiffrent Curves pass through the Equilibrium", TRUE),
            checkboxInput("isSHP", "Separating Hyperplane", TRUE),
            checkboxInput("isCC", "Contract Curve", TRUE)
        ), 

        mainPanel(
            plotOutput("distPlot")
        )
    )
)

server <- function(input, output) {
    # input$isIC_Iが変更されたら、見えないタブを切り替える
    observeEvent(input$isIC_I, {
        updateTabsetPanel(inputId = "tab4core", selected = ifelse(input$isIC_I, "true", "false"))
    })

    output$distPlot <- renderPlot({
        # inputはReactiveValuesクラスで$で参照できる変数を陽に持たないため、withやattachが使えない
        drawEdgeworthBox(input$A, input$B, CC=input$isCC, SHP=input$isSHP, IC_I=input$isIC_I,
            IC_E=input$isIC_E, CORE=input$isCore, IP=input$isIP)
    }, width=500, height=500)
}

app <- shinyApp(ui = ui, server = server)
runApp(app)