Sys.getenv()在Shiny Apps中返回空

时间:2016-04-26 00:32:44

标签: r shiny

注意 我编辑了这个问题,因为使用PG_HOST导致了混淆,但精神是相同的

我正在运行一个需要读取一些环境变量的闪亮应用。

这些变量是在闪亮服务器启动之前定义的。例如

export APPLE=apple
export PENCIL=pencil

global.R(或server.R的开头是相同的)我写了以下代码:

manzana <- Sys.getenv('APPLE')
lapiz <- Sys.getenv('PENCIL')

但这些变量是空的。

如果我在R控制台中运行该代码,则两者都返回正确的值。

这不行吗? Whay与R控制台和闪亮的应用程序不同? 我如何获得真实的环境变量(在这个假的例子中$APPLE$PENCIL)? 配置闪亮应用程序的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

第一步是了解反应性。看看闪亮的教程。

使用你的例子......让应用程序更新并设置可以被称为多种方式的变量....

private void makingCalenderDataList(int mm, int yy) {

    // clear previous data
    list.clear();

    int trailingSpaces = 0;
    int daysInPrevMonth = 0;
    int prevMonth = 0;
    int prevYear = 0;
    int nextMonth = 0;
    int nextYear = 0;

    int currentSelectedMonth = mm - 1;
    // String currentMonthName = mData.getMonthAsString(currentSelectedMonth);
    daysInMonth = mData.getNumberOfDaysOfMonth(currentSelectedMonth);

    GregorianCalendar cal = new GregorianCalendar(yy, currentSelectedMonth, 1);
   // Log.d(tag, "Gregorian Calendar:= " + cal.getTime().toString());

    if (currentSelectedMonth == 11) {
        prevMonth = currentSelectedMonth - 1;
        daysInPrevMonth = mData.getNumberOfDaysOfMonth(prevMonth);
        nextMonth = 0;
        prevYear = yy;
        nextYear = yy + 1;
        // Log.d(tag, "*->PrevYear: " + prevYear + " PrevMonth:" + prevMonth + " NextMonth: " + nextMonth + " NextYear: " + nextYear);
    } else if (currentSelectedMonth == 0) {
        prevMonth = 11;
        prevYear = yy - 1;
        nextYear = yy;
        daysInPrevMonth = mData.getNumberOfDaysOfMonth(prevMonth);
        nextMonth = 1;
        // Log.d(tag, "**--> PrevYear: " + prevYear + " PrevMonth:" + prevMonth + " NextMonth: " + nextMonth + " NextYear: " + nextYear);
    } else {
        prevMonth = currentSelectedMonth - 1;
        nextMonth = currentSelectedMonth + 1;
        nextYear = yy;
        prevYear = yy;
        daysInPrevMonth = mData.getNumberOfDaysOfMonth(prevMonth);
        //  Log.d(tag, "***---> PrevYear: " + prevYear + " PrevMonth:" + prevMonth + " NextMonth: " + nextMonth + " NextYear: " + nextYear);
    }

    int currentWeekDay = cal.get(Calendar.DAY_OF_WEEK) - 1;
    trailingSpaces = currentWeekDay;


    if (cal.isLeapYear(cal.get(Calendar.YEAR)))
        if (mm == 2)
            ++daysInMonth;
        else if (mm == 3)
            ++daysInPrevMonth;


    // Trailing Month days
    for (int i = 0; i < trailingSpaces; i++) {

        list.add(String
                .valueOf((daysInPrevMonth - trailingSpaces + DAY_OFFSET)
                        + i)
                + "-Trailing"
                + "-"
                + mData.getMonthAsString(prevMonth)
                + "-"
                + prevYear);
    }


    // Current Month Days
    for (int i = 1; i <= daysInMonth; i++) {

        //  Log.d("imon", "monthOfCurrentDate: " + monthOfCurrentDate + " monthOfCurrentDate " + (currentSelectedMonth + 1));
        // if the date is today's date then make it different color
        if (i == mData.getCurrentDayOfMonth() && monthOfCurrentDate == (currentSelectedMonth + 1)) {
            list.add(String.valueOf(i) + "-Today" + "-"
                    + mData.getMonthAsString(currentSelectedMonth) + "-" + yy);


        }
        // if current month == from month
        // then we have to check whether the CurrentDateDay is greater than or equal fromDateDay
        else if ((currentSelectedMonth + 1) == Integer.parseInt(fromDateMonth)) {
            if ((i >= Integer.parseInt(fromDateDay))) {
                list.add(String.valueOf(i) + "-Events" + "-"
                        + mData.getMonthAsString(currentSelectedMonth) + "-" + yy);
            } else {
                list.add(String.valueOf(i) + "-CurrentMonth" + "-"
                        + mData.getMonthAsString(currentSelectedMonth) + "-" + yy);
            }

        }
        // if current month > from month && current month <To month
        // then we don't have to check
        // all days will be enlisted as events
        else if ((currentSelectedMonth + 1) > Integer.parseInt(fromDateMonth) && (currentSelectedMonth + 1) < Integer.parseInt(toDateMonth)) {
            list.add(String.valueOf(i) + "-Events" + "-"
                    + mData.getMonthAsString(currentSelectedMonth) + "-" + yy);

        }
        //  current month == To month
        // then we have to check whether the CurrentDateDay is smaller than or equal toDateDay
        else if ((currentSelectedMonth + 1) == Integer.parseInt(toDateMonth)) {
            if ((i <= Integer.parseInt(toDateDay))) {
                list.add(String.valueOf(i) + "-Events" + "-"
                        + mData.getMonthAsString(currentSelectedMonth) + "-" + yy);
            } else {
                list.add(String.valueOf(i) + "-CurrentMonth" + "-"
                        + mData.getMonthAsString(currentSelectedMonth) + "-" + yy);
            }

        } else {
            list.add(String.valueOf(i) + "-CurrentMonth" + "-"
                    + mData.getMonthAsString(currentSelectedMonth) + "-" + yy);
        }
    }


    // Leading Month days
    for (int i = 0; i < list.size() % 7; i++) {
        Log.d(tag, "NEXT MONTH:= " + mData.getMonthAsString(nextMonth));
        list.add(String.valueOf(i + 1) + "-LeadingDates" + "-"
                + mData.getMonthAsString(nextMonth) + "-" + nextYear);
    }

    if (list.size() == 42) {
        mWeek6.setVisibility(View.VISIBLE);

    } else {
        mWeek6.setVisibility(View.INVISIBLE);
    }

}

结果: enter image description here