私はggvisを使用していて、UI側でselectInputを使用して次のコードを使用して、ユーザーが塗りと形を指定する変数を選択できるようにしました(inputIdはそれぞれ塗りつぶしと形です)。私は、プロットが、ユーザが選択した場合に、一定の塗りつぶしまたは形状を有する能力を有することを望む。このコードの他の部分は、私がしたい正確にどのように動作しますが、私はif文でオプションを選択すると、次のエラーでアプリがクラッシュ:ユーザー指定の塗りつぶし
Error in eval: could not find function ":="
は、私は伝説を抑制するためならば、私は正しい構文を持って知っていますとif/elseステートメントを指定し、fillを定数として指定します(fill:= "black")。
ご協力いただければ幸いです。
vis <- reactive({
fillvar <- prop("fill", as.symbol(input$fill))
shapevar <- prop("shape", as.symbol(input$shape))
filteredData() %>%
ggvis(x = xvar, y = yvar) %>%
layer_points(size.hover := 200,
fillOpacity:= 0.5, fillOpacity.hover := 1,
# Allows for points to be consistent if the user desires
if (input$fill == "All Points Black") {
fill := "black"}
else {
fill = fillvar}
,
if (input$shape == "All Points Circles") {
shape := "circle"}
else {
shape = shapevar}
,
key := ~ID
) %>%
# Adds legends to the Plot in designated locations
add_legend("fill", title = as.character(fillvar)) %>%
add_legend("shape", title = as.character(shapevar), properties = legend_props(legend = list(y=300))) %>%
# Adds the previously defined tool_tip my_tooltip
add_tooltip(my_tooltip, "hover") %>%
# Specifies the size of the plot
set_options(width = 800, height = 400, duration = 0)
})
#Actually plots the data
vis %>% bind_shiny("plot1")
ggvisステートメントの前にif/elseロジックを2つの変数に展開することができれば、それはうまくいくはずです。 –
@warmoverflowこれはうまくいかなかった。 if else文をggvisの外に置くと、constantオプションが選択されても同じエラーが返されます。 – User247365
ggvisの外でロジックを試してみるかもしれません。また、 'prop'を使う前にロジックを試してみるかもしれません。あなたのロジックに基づいて、マッピング変数である 'as.name(input $ fill)'または '' black "のいずれかの変数を作ります。この新しい変数を、例えば 'prop(" fill "、newvar)'のような 'layer_points'内の' prop'に渡し、 ':='を一緒に避けてください。 – aosmith