Gvis图不会呈现“闪亮”

时间:2018-06-26 07:17:38

标签: r shiny

在这里,我似乎有些麻烦,无法生成简单的折线图。

我试图通过用户输入显示每个图形,但是似乎无法获得简单的折线图。

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp2"
        mc:Ignorable="d"
        Title="MainWindow" Height="300" Width="300">
    <Window.Resources>
        <CollectionViewSource x:Key="outer" />
        <CollectionViewSource x:Key="inner" />
    </Window.Resources>
    <Grid>
        <ListBox ItemsSource="{Binding Source={StaticResource outer}}">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <ListBox ItemsSource="{Binding Source={StaticResource inner}}" 
                             MaxHeight="100" ScrollViewer.VerticalScrollBarVisibility="Disabled" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Window>

rownames(futures_data)给出每一行数据的日期。

head(futures_data)

                   Corn        Wheat     Soybeans
2001-01-02 -0.019417476 -0.011627907 -0.009009009
2001-01-03  0.012101210  0.025339367  0.004545455
2001-01-04  0.000000000  0.003530450 -0.010055304
2001-01-05 -0.017391304 -0.004397537 -0.005586592
2001-01-08 -0.001106195  0.000000000  0.003064351
2001-01-09  0.007751938  0.007067138  0.008655804

使用server.R library(shiny) library(googleVis) server <- function(input, output){ futures <- as.data.frame(futures_data) fut <- cbind.data.frame(x=futures$Corn, y=rownames(futures)) output$abc <- renderText({ "sjdaflkjsd" }) output$g1 <- renderPlot({ gvisLineChart( data=fut ,xvar="x" ,yvar="y" ) }) output$t1 <- renderTable({ head(futures) }) } 时,表格也会消失。

output$g1 <- renderGvis({})

我的问题是我做错了什么?

预先感谢,非常欢迎其他批评

1 个答案:

答案 0 :(得分:1)

您需要使用适当的renderOutput函数:

ui.R

htmlOutput("g1")

server.R

output$g1 <- renderGvis({
  gvisLineChart(
    data = fut,
    xvar = "x",
    yvar = "y" 
  )
})

然后一个已知的问题是,您的输出将不会显示在RStudio浏览器中,无法运行您的应用程序并在传统的浏览器(Firefox,Chrome ...)中打开它。

在y轴上绘制带有日期的数据时,可能还会出现问题。但是,当日期位于x轴上时,效果很好。

相关问题